brlapi_keys - Reading key presses
Contents
Detailed Description
Once brlapi_enterTtyMode() has been called, the application can call brlapi_readKey() to read key
presses. Either key codes (see TypesandDefinesforBrlAPIKeyCodes)orcommandswillbereturned,dependingonparametersgiventobrlapi_enterTtyMode().
Key presses are buffered, so that calling brlapi_readKey() in non-blocking mode from time to time should
suffice.
Enumeration Type Documentation
enumbrlapi_rangeType_t
types of key ranges
Enumeratorbrlapi_rangeType_all
all keys, code must be 0
brlapi_rangeType_type
all keys of a given type
brlapi_rangeType_command
all keys of a given command block, i.e. matching the key type and command parts
brlapi_rangeType_key
a given key with any flags
brlapi_rangeType_code
a given key code
Function Documentation
intBRLAPI_STDCALLbrlapi__acceptAllKeys(brlapi_handle_t*handle)intBRLAPI_STDCALLbrlapi__acceptKeyRanges(brlapi_handle_t*handle,constbrlapi_range_tranges[],unsignedintcount)intBRLAPI_STDCALLbrlapi__acceptKeys(brlapi_handle_t*handle,brlapi_rangeType_ttype,constbrlapi_keyCode_tkeys[],unsignedintcount)intBRLAPI_STDCALLbrlapi__ignoreAllKeys(brlapi_handle_t*handle)intBRLAPI_STDCALLbrlapi__ignoreKeyRanges(brlapi_handle_t*handle,constbrlapi_range_tranges[],unsignedintcount)intBRLAPI_STDCALLbrlapi__ignoreKeys(brlapi_handle_t*handle,brlapi_rangeType_ttype,constbrlapi_keyCode_tkeys[],unsignedintcount)intBRLAPI_STDCALLbrlapi__readKey(brlapi_handle_t*handle,intwait,brlapi_keyCode_t*code)intBRLAPI_STDCALLbrlapi__readKeyWithTimeout(brlapi_handle_t*handle,inttimeout_ms,brlapi_keyCode_t*code)intBRLAPI_STDCALLbrlapi_acceptKeyRanges(constbrlapi_range_tranges[],unsignedintcount)
Accept some key presses from the braille keyboard
This function asks the server to return the provided key ranges (inclusive) to the application, and not
give them to brltty.
The sets of such keys are reset on brlapi_enterTtyMode call.
Parametersranges key ranges, which are inclusive, see TypesandDefinesforBrlAPIKeyCodesaboutkeyrangescountnumberofrangesintBRLAPI_STDCALLbrlapi_acceptKeys(brlapi_rangeType_ttype,constbrlapi_keyCode_tkeys[],unsignedintcount)
Accept some key presses from the braille keyboard
This function asks the server to give the provided keys to the application, and not give them to brltty.
The sets of such keys are reset on brlapi_enterTtyMode call.
Parameterstype type of keys to be ignored
keys array of keys to be ignored
count number of keys
intBRLAPI_STDCALLbrlapi_describeKeyCode(brlapi_keyCode_tcode,brlapi_describedKeyCode_t*description)
Describe the components of a key code.
Parameterscode the keycode to be described
description pointer to the structure that receives the description
Returns
0 on success, -1 on error
intBRLAPI_STDCALLbrlapi_expandKeyCode(brlapi_keyCode_tcode,brlapi_expandedKeyCode_t*expansion)
Expand the components of a key code
Parameterscode the key code to be expanded
expansion pointer to the structure that receives the components
Returns
0 on success, -1 on error
intBRLAPI_STDCALLbrlapi_ignoreKeyRanges(constbrlapi_range_tranges[],unsignedintcount)
Ignore some key presses from the braille keyboard
This function asks the server to give the provided key ranges to brltty, rather than returning them to
the application via brlapi_readKey().
The sets of such keys are reset on brlapi_enterTtyMode call.
Parametersranges key ranges, which are inclusive, see TypesandDefinesforBrlAPIKeyCodesaboutkeyrangescountnumberofrangesintBRLAPI_STDCALLbrlapi_ignoreKeys(brlapi_rangeType_ttype,constbrlapi_keyCode_tkeys[],unsignedintcount)
Ignore some key presses from the braille keyboard
This function asks the server to give the provided keys to brltty, rather than returning them to the
application via brlapi_readKey().
The sets of such keys are reset on brlapi_enterTtyMode call.
Parameterstype type of keys to be ignored
keys array of keys to be ignored
count number of keys
intBRLAPI_STDCALLbrlapi_readKey(intwait,brlapi_keyCode_t*code)
Read a key from the braille keyboard
This function returns one key press's code.
If NULL or '' was given to brlapi_enterTtyMode(), a brltty command is returned, as described in the
documentation for brlapi_keyCode_t . It is hence pretty driver-independent, and should be used by default
when no other option is possible.
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
brlapi_ignoreKeys()
If a driver name was given to brlapi_enterTtyMode(), a driver-specific keycode is returned, as specified
by the braille driver, usually in <brltty/brldefs-xy> 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 brlapi_getDriverName() before getting tty control is a pretty good idea.
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.
Parameterswait tells whether the call should block until a key is pressed (1) or should only probe key presses
(0);
code holds the key code if a key press is indeed read.
Returns
-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.
Programming hints:
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.
Else, you'll probably want to use the file descriptor returned by brlapi_openConnection() or
brlapi_getFileDescriptor() in your 'big polling loop'. For instance:
• in a select() loop, just add it to the readfds and exceptfds file descriptor sets;
• in a gtk or atspi application, use g_io_add_watch(fileDescriptor, G_IO_IN|G_IO_ERR|G_IO_HUP, f, data)
for adding a callback called f;
• in an Xt/Xaw/motif-based application, use XtAppAddInput(app_context, fileDescriptor,
XtInputReadMask|XtInputExceptMask, f, data)
• etc.
and then, when you detect inbound trafic on the file descriptor, do something like this:
while (brlapi_readKey(0, &code) { // process keycode code // ... }
The while loop is needed for processing all pending key presses, else some of them may be left in
libbrlapi's internal key buffer and you wouldn't get them immediately.
Note
If the read is interrupted by a signal or by a parameter change notification, brlapi_readKey() will
return -1, brlapi_errno will be BRLAPI_ERROR_LIBCERR and errno will be EINTR.
intBRLAPI_STDCALLbrlapi_readKeyWithTimeout(inttimeout_ms,brlapi_keyCode_t*code)
Read a key from the braille keyboard, unless a timeout expires
This function works like brlapi_readKey, except that parameter wait is replaced by a timeout_ms parameter
Parameterstimeout_ms specifies how long the function should wait for a keypress.
code holds the key code if a key press is indeed read.
Returns
-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.
If the timeout expires without any key being pressed, 0 is returned.
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.
If timeout_ms is set to a negative value, this function behaves like brlapi_readKey, i.e. it uses an
infinite timeout.
Macro Definition Documentation
#definebrlapi__acceptAllKeys(handle)brlapi__acceptKeys(handle,brlapi_rangeType_all,NULL,0)#definebrlapi__ignoreAllKeys(handle)brlapi__ignoreKeys(handle,brlapi_rangeType_all,NULL,0)intBRLAPI_STDCALLbrlapi_acceptAllKeys(void)brlapi_acceptKeys(brlapi_rangeType_all,NULL,0)
Accept all key presses from the braille keyboard
This function asks the server to give all keys to the application, and not give them to brltty.
Warning: after calling this function, make sure to call brlapi_ignoreKeys() for ignoring important keys
like BRL_CMD_SWITCHVT_PREV/NEXT and such.
The sets of such keys are reset on brlapi_enterTtyMode call.
intBRLAPI_STDCALLbrlapi_ignoreAllKeys(void)brlapi_ignoreKeys(brlapi_rangeType_all,NULL,0)
Ignore all key presses from the braille keyboard
This function asks the server to give all keys to brltty, rather than returning them to the application
via brlapi_readKey().
The sets of such keys are reset on brlapi_enterTtyMode call.
#defineBRLAPI_UC_ROW0x2800UL
Unicode braille row
Name
brlapi_keys - Reading key presses
- How to read key presses from the braille terminal.
Synopsis
DataStructures
struct brlapi_expandedKeyCode_t
struct brlapi_describedKeyCode_t
struct brlapi_range_tMacros
#define brlapi_ignoreAllKeys() brlapi_ignoreKeys(brlapi_rangeType_all, NULL, 0)
#define brlapi_acceptAllKeys() brlapi_acceptKeys(brlapi_rangeType_all, NULL, 0)
#define BRLAPI_UC_ROW 0x2800UL
#define brlapi__ignoreAllKeys(handle) brlapi__ignoreKeys(handle, brlapi_rangeType_all, NULL, 0)
#define brlapi__acceptAllKeys(handle) brlapi__acceptKeys(handle, brlapi_rangeType_all, NULL, 0)
Enumerations
enum brlapi_rangeType_t { brlapi_rangeType_all, brlapi_rangeType_type, brlapi_rangeType_command,
brlapi_rangeType_key, brlapi_rangeType_code }
Functions
int BRLAPI_STDCALLbrlapi_expandKeyCode (brlapi_keyCode_t code, brlapi_expandedKeyCode_t *expansion)
int BRLAPI_STDCALLbrlapi_describeKeyCode (brlapi_keyCode_t code, brlapi_describedKeyCode_t *description)
int BRLAPI_STDCALLbrlapi_readKey (int wait, brlapi_keyCode_t *code)
int BRLAPI_STDCALLbrlapi__readKey (brlapi_handle_t *handle, int wait, brlapi_keyCode_t *code)
int BRLAPI_STDCALLbrlapi_readKeyWithTimeout (int timeout_ms, brlapi_keyCode_t *code)
int BRLAPI_STDCALLbrlapi__readKeyWithTimeout (brlapi_handle_t *handle, int timeout_ms, brlapi_keyCode_t
*code)
int BRLAPI_STDCALLbrlapi_ignoreKeys (brlapi_rangeType_t type, const brlapi_keyCode_t keys[], unsigned
int count)
int BRLAPI_STDCALLbrlapi__ignoreKeys (brlapi_handle_t *handle, brlapi_rangeType_t type, const
brlapi_keyCode_t keys[], unsigned int count)
int BRLAPI_STDCALLbrlapi_acceptKeys (brlapi_rangeType_t type, const brlapi_keyCode_t keys[], unsigned
int count)
int BRLAPI_STDCALLbrlapi__acceptKeys (brlapi_handle_t *handle, brlapi_rangeType_t type, const
brlapi_keyCode_t keys[], unsigned int count)
int BRLAPI_STDCALLbrlapi__ignoreAllKeys (brlapi_handle_t *handle)
int BRLAPI_STDCALLbrlapi__acceptAllKeys (brlapi_handle_t *handle)
int BRLAPI_STDCALLbrlapi_ignoreKeyRanges (const brlapi_range_t ranges[], unsigned int count)
int BRLAPI_STDCALLbrlapi__ignoreKeyRanges (brlapi_handle_t *handle, const brlapi_range_t ranges[],
unsigned int count)
int BRLAPI_STDCALLbrlapi_acceptKeyRanges (const brlapi_range_t ranges[], unsigned int count)
int BRLAPI_STDCALLbrlapi__acceptKeyRanges (brlapi_handle_t *handle, const brlapi_range_t ranges[],
unsigned int count)
