.TH "brlapi_keys" 3 "Version 0.8" "BrlAPI" \" -*- nroff -*- .ad l .nh .SH NAME brlapi_keys \- Reading key presses .PP \- How to read key presses from the braille terminal\&. .SH SYNOPSIS .br .PP .SS "Data Structures" .in +1c .ti -1c .RI "struct \fBbrlapi_expandedKeyCode_t\fP" .br .ti -1c .RI "struct \fBbrlapi_describedKeyCode_t\fP" .br .ti -1c .RI "struct \fBbrlapi_range_t\fP" .br .in -1c .SS "Macros" .in +1c .ti -1c .RI "#define \fBbrlapi_ignoreAllKeys\fP() \fBbrlapi_ignoreKeys\fP(\fBbrlapi_rangeType_all\fP, NULL, 0)" .br .ti -1c .RI "#define \fBbrlapi_acceptAllKeys\fP() \fBbrlapi_acceptKeys\fP(\fBbrlapi_rangeType_all\fP, NULL, 0)" .br .ti -1c .RI "#define \fBBRLAPI_UC_ROW\fP 0x2800UL" .br .ti -1c .RI "#define \fBbrlapi__ignoreAllKeys\fP(handle) \fBbrlapi__ignoreKeys\fP(handle, \fBbrlapi_rangeType_all\fP, NULL, 0)" .br .ti -1c .RI "#define \fBbrlapi__acceptAllKeys\fP(handle) \fBbrlapi__acceptKeys\fP(handle, \fBbrlapi_rangeType_all\fP, NULL, 0)" .br .in -1c .SS "Enumerations" .in +1c .ti -1c .RI "enum \fBbrlapi_rangeType_t\fP { \fBbrlapi_rangeType_all\fP, \fBbrlapi_rangeType_type\fP, \fBbrlapi_rangeType_command\fP, \fBbrlapi_rangeType_key\fP, \fBbrlapi_rangeType_code\fP }" .br .in -1c .SS "Functions" .in +1c .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi_expandKeyCode\fP (\fBbrlapi_keyCode_t\fP code, \fBbrlapi_expandedKeyCode_t\fP *expansion)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi_describeKeyCode\fP (\fBbrlapi_keyCode_t\fP code, \fBbrlapi_describedKeyCode_t\fP *description)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi_readKey\fP (int wait, \fBbrlapi_keyCode_t\fP *code)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi__readKey\fP (\fBbrlapi_handle_t\fP *handle, int wait, \fBbrlapi_keyCode_t\fP *code)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi_readKeyWithTimeout\fP (int timeout_ms, \fBbrlapi_keyCode_t\fP *code)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi__readKeyWithTimeout\fP (\fBbrlapi_handle_t\fP *handle, int timeout_ms, \fBbrlapi_keyCode_t\fP *code)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi_ignoreKeys\fP (\fBbrlapi_rangeType_t\fP type, const \fBbrlapi_keyCode_t\fP keys[], unsigned int count)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi__ignoreKeys\fP (\fBbrlapi_handle_t\fP *handle, \fBbrlapi_rangeType_t\fP type, const \fBbrlapi_keyCode_t\fP keys[], unsigned int count)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi_acceptKeys\fP (\fBbrlapi_rangeType_t\fP type, const \fBbrlapi_keyCode_t\fP keys[], unsigned int count)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi__acceptKeys\fP (\fBbrlapi_handle_t\fP *handle, \fBbrlapi_rangeType_t\fP type, const \fBbrlapi_keyCode_t\fP keys[], unsigned int count)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi__ignoreAllKeys\fP (\fBbrlapi_handle_t\fP *handle)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi__acceptAllKeys\fP (\fBbrlapi_handle_t\fP *handle)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi_ignoreKeyRanges\fP (const \fBbrlapi_range_t\fP ranges[], unsigned int count)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi__ignoreKeyRanges\fP (\fBbrlapi_handle_t\fP *handle, const \fBbrlapi_range_t\fP ranges[], unsigned int count)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi_acceptKeyRanges\fP (const \fBbrlapi_range_t\fP ranges[], unsigned int count)" .br .ti -1c .RI "int \fBBRLAPI_STDCALL\fP \fBbrlapi__acceptKeyRanges\fP (\fBbrlapi_handle_t\fP *handle, const \fBbrlapi_range_t\fP ranges[], unsigned int count)" .br .in -1c .SH "Detailed Description" .PP Once \fBbrlapi_enterTtyMode()\fP has been called, the application can call \fBbrlapi_readKey()\fP to read key presses\&. Either key codes (see \fBTypes and Defines for\fIBrlAPI\fP Key Codes\fP) or commands will be returned, depending on parameters given to \fBbrlapi_enterTtyMode()\fP\&. .PP Key presses are buffered, so that calling \fBbrlapi_readKey()\fP in non-blocking mode from time to time should suffice\&. .SH "Macro Definition Documentation" .PP .SS "#define brlapi__acceptAllKeys(handle) \fBbrlapi__acceptKeys\fP(handle, \fBbrlapi_rangeType_all\fP, NULL, 0)" .SS "#define brlapi__ignoreAllKeys(handle) \fBbrlapi__ignoreKeys\fP(handle, \fBbrlapi_rangeType_all\fP, NULL, 0)" .SS "int \fBBRLAPI_STDCALL\fP brlapi_acceptAllKeys(void) \fBbrlapi_acceptKeys\fP(\fBbrlapi_rangeType_all\fP, NULL, 0)" Accept all key presses from the braille keyboard .PP This function asks the server to give all keys to the application, and not give them to \fIbrltty\fP\&. .PP Warning: after calling this function, make sure to call \fBbrlapi_ignoreKeys()\fP for ignoring important keys like BRL_CMD_SWITCHVT_PREV/NEXT and such\&. .PP The sets of such keys are reset on brlapi_enterTtyMode call\&. .SS "int \fBBRLAPI_STDCALL\fP brlapi_ignoreAllKeys(void) \fBbrlapi_ignoreKeys\fP(\fBbrlapi_rangeType_all\fP, NULL, 0)" Ignore all key presses from the braille keyboard .PP This function asks the server to give all keys to \fIbrltty\fP, rather than returning them to the application via \fBbrlapi_readKey()\fP\&. .PP The sets of such keys are reset on brlapi_enterTtyMode call\&. .SS "#define BRLAPI_UC_ROW 0x2800UL" Unicode braille row .SH "Enumeration Type Documentation" .PP .SS "enum \fBbrlapi_rangeType_t\fP" types of key ranges .PP \fBEnumerator\fP .in +1c .TP \fB\fIbrlapi_rangeType_all \fP\fP all keys, code must be 0 .TP \fB\fIbrlapi_rangeType_type \fP\fP all keys of a given type .TP \fB\fIbrlapi_rangeType_command \fP\fP all keys of a given command block, i\&.e\&. matching the key type and command parts .TP \fB\fIbrlapi_rangeType_key \fP\fP a given key with any flags .TP \fB\fIbrlapi_rangeType_code \fP\fP a given key code .SH "Function Documentation" .PP .SS "int \fBBRLAPI_STDCALL\fP brlapi__acceptAllKeys (\fBbrlapi_handle_t\fP * handle)" .SS "int \fBBRLAPI_STDCALL\fP brlapi__acceptKeyRanges (\fBbrlapi_handle_t\fP * handle, const \fBbrlapi_range_t\fP ranges[], unsigned int count)" .SS "int \fBBRLAPI_STDCALL\fP brlapi__acceptKeys (\fBbrlapi_handle_t\fP * handle, \fBbrlapi_rangeType_t\fP type, const \fBbrlapi_keyCode_t\fP keys[], unsigned int count)" .SS "int \fBBRLAPI_STDCALL\fP brlapi__ignoreAllKeys (\fBbrlapi_handle_t\fP * handle)" .SS "int \fBBRLAPI_STDCALL\fP brlapi__ignoreKeyRanges (\fBbrlapi_handle_t\fP * handle, const \fBbrlapi_range_t\fP ranges[], unsigned int count)" .SS "int \fBBRLAPI_STDCALL\fP brlapi__ignoreKeys (\fBbrlapi_handle_t\fP * handle, \fBbrlapi_rangeType_t\fP type, const \fBbrlapi_keyCode_t\fP keys[], unsigned int count)" .SS "int \fBBRLAPI_STDCALL\fP brlapi__readKey (\fBbrlapi_handle_t\fP * handle, int wait, \fBbrlapi_keyCode_t\fP * code)" .SS "int \fBBRLAPI_STDCALL\fP brlapi__readKeyWithTimeout (\fBbrlapi_handle_t\fP * handle, int timeout_ms, \fBbrlapi_keyCode_t\fP * code)" .SS "int \fBBRLAPI_STDCALL\fP brlapi_acceptKeyRanges (const \fBbrlapi_range_t\fP ranges[], unsigned int count)" Accept some key presses from the braille keyboard .PP This function asks the server to return the provided key ranges (inclusive) to the application, and not give them to \fIbrltty\fP\&. .PP The sets of such keys are reset on brlapi_enterTtyMode call\&. .PP \fBParameters\fP .RS 4 \fIranges\fP key ranges, which are inclusive, see \fBTypes and Defines for\fIBrlAPI\fP Key Codes\fP about key ranges .br \fIcount\fP number of ranges .RE .PP .SS "int \fBBRLAPI_STDCALL\fP brlapi_acceptKeys (\fBbrlapi_rangeType_t\fP type, const \fBbrlapi_keyCode_t\fP keys[], unsigned int count)" Accept some key presses from the braille keyboard .PP This function asks the server to give the provided keys to the application, and not give them to \fIbrltty\fP\&. .PP The sets of such keys are reset on brlapi_enterTtyMode call\&. .PP \fBParameters\fP .RS 4 \fItype\fP type of keys to be ignored .br \fIkeys\fP array of keys to be ignored .br \fIcount\fP number of keys .RE .PP .SS "int \fBBRLAPI_STDCALL\fP brlapi_describeKeyCode (\fBbrlapi_keyCode_t\fP code, \fBbrlapi_describedKeyCode_t\fP * description)" Describe the components of a key code\&. .PP \fBParameters\fP .RS 4 \fIcode\fP the keycode to be described .br \fIdescription\fP pointer to the structure that receives the description .RE .PP \fBReturns\fP .RS 4 0 on success, -1 on error .RE .PP .SS "int \fBBRLAPI_STDCALL\fP brlapi_expandKeyCode (\fBbrlapi_keyCode_t\fP code, \fBbrlapi_expandedKeyCode_t\fP * expansion)" Expand the components of a key code .PP \fBParameters\fP .RS 4 \fIcode\fP the key code to be expanded .br \fIexpansion\fP pointer to the structure that receives the components .RE .PP \fBReturns\fP .RS 4 0 on success, -1 on error .RE .PP .SS "int \fBBRLAPI_STDCALL\fP brlapi_ignoreKeyRanges (const \fBbrlapi_range_t\fP ranges[], unsigned int count)" Ignore some key presses from the braille keyboard .PP This function asks the server to give the provided key ranges to \fIbrltty\fP, rather than returning them to the application via \fBbrlapi_readKey()\fP\&. .PP The sets of such keys are reset on brlapi_enterTtyMode call\&. .PP \fBParameters\fP .RS 4 \fIranges\fP key ranges, which are inclusive, see \fBTypes and Defines for\fIBrlAPI\fP Key Codes\fP about key ranges .br \fIcount\fP number of ranges .RE .PP .SS "int \fBBRLAPI_STDCALL\fP brlapi_ignoreKeys (\fBbrlapi_rangeType_t\fP type, const \fBbrlapi_keyCode_t\fP keys[], unsigned int count)" Ignore some key presses from the braille keyboard .PP This function asks the server to give the provided keys to \fIbrltty\fP, rather than returning them to the application via \fBbrlapi_readKey()\fP\&. .PP The sets of such keys are reset on brlapi_enterTtyMode call\&. .PP \fBParameters\fP .RS 4 \fItype\fP type of keys to be ignored .br \fIkeys\fP array of keys to be ignored .br \fIcount\fP number of keys .RE .PP .SS "int \fBBRLAPI_STDCALL\fP brlapi_readKey (int wait, \fBbrlapi_keyCode_t\fP * code)" Read a key from the braille keyboard .PP This function returns one key press's code\&. .PP If NULL or '' was given to \fBbrlapi_enterTtyMode()\fP, a \fIbrltty\fP command is returned, as described in the documentation for \fBbrlapi_keyCode_t\fP \&. It is hence pretty driver-independent, and should be used by default when no other option is possible\&. .PP By default, all commands but those which restart drivers and switch virtual terminals are returned to the application and not to brltty\&. If the application doesn't want to see some command events, it should call \fBbrlapi_ignoreKeys()\fP .PP If a driver name was given to \fBbrlapi_enterTtyMode()\fP, a driver-specific keycode is returned, as specified by the braille driver, usually in where xy is the driver's code\&. It generally corresponds to the very code that the terminal tells to the driver\&. This should only be used by applications which are dedicated to a particular braille terminal\&. Hence, checking the terminal type thanks to a call to \fBbrlapi_getDriverName()\fP before getting tty control is a pretty good idea\&. .PP By default, all the keypresses will be passed to the client, none will go through brltty, so the application will have to handle console switching itself for instance\&. .PP \fBParameters\fP .RS 4 \fIwait\fP tells whether the call should block until a key is pressed (1) or should only probe key presses (0); .br \fIcode\fP holds the key code if a key press is indeed read\&. .RE .PP \fBReturns\fP .RS 4 -1 on error or signal interrupt and *code is then undefined, 0 if block was 0 and no key was pressed so far, or 1 and *code holds the key code\&. .RE .PP Programming hints: .PP If your application is only driven by braille command keypresses, you can just call brlapi_readKey(1, &code) so that it keeps blocking, waiting for keypresses\&. .PP Else, you'll probably want to use the file descriptor returned by \fBbrlapi_openConnection()\fP or \fBbrlapi_getFileDescriptor()\fP in your 'big polling loop'\&. For instance: .PP .IP "\(bu" 2 in a \fCselect()\fP loop, just add it to the \fCreadfds\fP and \fCexceptfds\fP file descriptor sets; .IP "\(bu" 2 in a gtk or atspi application, use \fCg_io_add_watch\fP(fileDescriptor, \fCG_IO_IN|G_IO_ERR|G_IO_HUP\fP, \fCf\fP, \fCdata\fP) for adding a callback called \fCf\fP; .IP "\(bu" 2 in an Xt/Xaw/motif-based application, use \fCXtAppAddInput\fP(app_context, \fCfileDescriptor\fP, \fCXtInputReadMask|XtInputExceptMask\fP, \fCf\fP, \fCdata\fP) .IP "\(bu" 2 etc\&. .PP .PP and then, when you detect inbound trafic on the file descriptor, do something like this: .PP while (brlapi_readKey(0, &code) { // process keycode code // \&.\&.\&. } .PP The \fCwhile\fP loop is needed for processing \fIall\fP pending key presses, else some of them may be left in libbrlapi's internal key buffer and you wouldn't get them immediately\&. .PP \fBNote\fP .RS 4 If the read is interrupted by a signal or by a parameter change notification, \fBbrlapi_readKey()\fP will return -1, brlapi_errno will be BRLAPI_ERROR_LIBCERR and errno will be EINTR\&. .RE .PP .SS "int \fBBRLAPI_STDCALL\fP brlapi_readKeyWithTimeout (int timeout_ms, \fBbrlapi_keyCode_t\fP * code)" Read a key from the braille keyboard, unless a timeout expires .PP This function works like brlapi_readKey, except that parameter \fIwait\fP is replaced by a \fItimeout_ms\fP parameter .PP \fBParameters\fP .RS 4 \fItimeout_ms\fP specifies how long the function should wait for a keypress\&. .br \fIcode\fP holds the key code if a key press is indeed read\&. .RE .PP \fBReturns\fP .RS 4 -1 on error, signal interrupt or parameter change notification and *code is then undefined, 0 if the timeout expired and no key was pressed, or 1 and *code holds the key code\&. .RE .PP If the timeout expires without any key being pressed, 0 is returned\&. .PP If timeout_ms is set to 0, this function looks for key events that have been already received, but does not wait at all if no event was received\&. .PP If timeout_ms is set to a negative value, this function behaves like brlapi_readKey, i\&.e\&. it uses an infinite timeout\&. .SH "Author" .PP Generated automatically by Doxygen for BrlAPI from the source code\&.