---
name: "brlapi_keys"
section: "3"
platform: "linux"
package: "libbrlapi-dev"
version: "6.7-3.1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/brlapi_keys"
---

# brlapi\_keys(3)

Reading key presses - How to read key presses from the braille terminal.

## NAME

brlapi\_keys - Reading key presses

 \- How to read key presses from the braille terminal.

## SYNOPSIS

### Data Structures

struct **brlapi\_expandedKeyCode\_t**\
 struct **brlapi\_describedKeyCode\_t**\
 struct **brlapi\_range\_t**\

### Macros

\#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\_STDCALL** **brlapi\_expandKeyCode** (**brlapi\_keyCode\_t** code, **brlapi\_expandedKeyCode\_t** \*expansion)\
 int **BRLAPI\_STDCALL** **brlapi\_describeKeyCode** (**brlapi\_keyCode\_t** code, **brlapi\_describedKeyCode\_t** \*description)\
 int **BRLAPI\_STDCALL** **brlapi\_readKey** (int wait, **brlapi\_keyCode\_t** \*code)\
 int **BRLAPI\_STDCALL** **brlapi\_\_readKey** (**brlapi\_handle\_t** \*handle, int wait, **brlapi\_keyCode\_t** \*code)\
 int **BRLAPI\_STDCALL** **brlapi\_readKeyWithTimeout** (int timeout\_ms, **brlapi\_keyCode\_t** \*code)\
 int **BRLAPI\_STDCALL** **brlapi\_\_readKeyWithTimeout** (**brlapi\_handle\_t** \*handle, int timeout\_ms, **brlapi\_keyCode\_t** \*code)\
 int **BRLAPI\_STDCALL** **brlapi\_ignoreKeys** (**brlapi\_rangeType\_t** type, const **brlapi\_keyCode\_t** keys\[\], unsigned int count)\
 int **BRLAPI\_STDCALL** **brlapi\_\_ignoreKeys** (**brlapi\_handle\_t** \*handle, **brlapi\_rangeType\_t** type, const **brlapi\_keyCode\_t** keys\[\], unsigned int count)\
 int **BRLAPI\_STDCALL** **brlapi\_acceptKeys** (**brlapi\_rangeType\_t** type, const **brlapi\_keyCode\_t** keys\[\], unsigned int count)\
 int **BRLAPI\_STDCALL** **brlapi\_\_acceptKeys** (**brlapi\_handle\_t** \*handle, **brlapi\_rangeType\_t** type, const **brlapi\_keyCode\_t** keys\[\], unsigned int count)\
 int **BRLAPI\_STDCALL** **brlapi\_\_ignoreAllKeys** (**brlapi\_handle\_t** \*handle)\
 int **BRLAPI\_STDCALL** **brlapi\_\_acceptAllKeys** (**brlapi\_handle\_t** \*handle)\
 int **BRLAPI\_STDCALL** **brlapi\_ignoreKeyRanges** (const **brlapi\_range\_t** ranges\[\], unsigned int count)\
 int **BRLAPI\_STDCALL** **brlapi\_\_ignoreKeyRanges** (**brlapi\_handle\_t** \*handle, const **brlapi\_range\_t** ranges\[\], unsigned int count)\
 int **BRLAPI\_STDCALL** **brlapi\_acceptKeyRanges** (const **brlapi\_range\_t** ranges\[\], unsigned int count)\
 int **BRLAPI\_STDCALL** **brlapi\_\_acceptKeyRanges** (**brlapi\_handle\_t** \*handle, const **brlapi\_range\_t** ranges\[\], unsigned int count)\

## Detailed Description

Once **brlapi\_enterTtyMode()** has been called, the application can call **brlapi\_readKey()** to read key presses. Either key codes (see **Types and Defines for***BrlAPI* **Key Codes***) or commands will be returned, depending on parameters given to* **brlapi\_enterTtyMode()***.*

*Key presses are buffered, so that calling* **brlapi\_readKey()** *in non-blocking mode from time to time should suffice.*

## Macro Definition Documentation

### #define brlapi\_\_acceptAllKeys(handle) brlapi\_\_acceptKeys(handle, brlapi\_rangeType\_all, NULL, 0)

### #define brlapi\_\_ignoreAllKeys(handle) brlapi\_\_ignoreKeys(handle, brlapi\_rangeType\_all, NULL, 0)

### int BRLAPI\_STDCALL brlapi\_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.*

### int BRLAPI\_STDCALL brlapi\_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.*

### #define BRLAPI\_UC\_ROW 0x2800UL

*Unicode braille row*

## Enumeration Type Documentation

### enum brlapi\_rangeType\_t

*types of key ranges*

**Enumerator**

- *brlapi\_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

### int BRLAPI\_STDCALL brlapi\_\_acceptAllKeys (brlapi\_handle\_t \* handle)

### int BRLAPI\_STDCALL brlapi\_\_acceptKeyRanges (brlapi\_handle\_t \* handle, const brlapi\_range\_t ranges\[\], unsigned int count)

### int BRLAPI\_STDCALL brlapi\_\_acceptKeys (brlapi\_handle\_t \* handle, brlapi\_rangeType\_t type, const brlapi\_keyCode\_t keys\[\], unsigned int count)

### int BRLAPI\_STDCALL brlapi\_\_ignoreAllKeys (brlapi\_handle\_t \* handle)

### int BRLAPI\_STDCALL brlapi\_\_ignoreKeyRanges (brlapi\_handle\_t \* handle, const brlapi\_range\_t ranges\[\], unsigned int count)

### int BRLAPI\_STDCALL brlapi\_\_ignoreKeys (brlapi\_handle\_t \* handle, brlapi\_rangeType\_t type, const brlapi\_keyCode\_t keys\[\], unsigned int count)

### int BRLAPI\_STDCALL brlapi\_\_readKey (brlapi\_handle\_t \* handle, int wait, brlapi\_keyCode\_t \* code)

### int BRLAPI\_STDCALL brlapi\_\_readKeyWithTimeout (brlapi\_handle\_t \* handle, int timeout\_ms, brlapi\_keyCode\_t \* code)

### int BRLAPI\_STDCALL brlapi\_acceptKeyRanges (const brlapi\_range\_t ranges\[\], unsigned int count)

*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.*

**Parameters**

*ranges key ranges, which are inclusive, see* **Types and Defines for***BrlAPI* **Key Codes** *about key ranges* \
 *count number of ranges*

### int BRLAPI\_STDCALL brlapi\_acceptKeys (brlapi\_rangeType\_t type, const brlapi\_keyCode\_t keys\[\], unsigned int count)

*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.*

**Parameters**

*type type of keys to be ignored* \
 *keys array of keys to be ignored* \
 *count number of keys*

### int BRLAPI\_STDCALL brlapi\_describeKeyCode (brlapi\_keyCode\_t code, brlapi\_describedKeyCode\_t \* description)

*Describe the components of a key code.*

**Parameters**

*code the keycode to be described* \
 *description pointer to the structure that receives the description*

**Returns**

*0 on success, -1 on error*

### int BRLAPI\_STDCALL brlapi\_expandKeyCode (brlapi\_keyCode\_t code, brlapi\_expandedKeyCode\_t \* expansion)

*Expand the components of a key code*

**Parameters**

*code the key code to be expanded* \
 *expansion pointer to the structure that receives the components*

**Returns**

*0 on success, -1 on error*

### int BRLAPI\_STDCALL brlapi\_ignoreKeyRanges (const brlapi\_range\_t ranges\[\], unsigned int count)

*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.*

**Parameters**

*ranges key ranges, which are inclusive, see* **Types and Defines for***BrlAPI* **Key Codes** *about key ranges* \
 *count number of ranges*

### int BRLAPI\_STDCALL brlapi\_ignoreKeys (brlapi\_rangeType\_t type, const brlapi\_keyCode\_t keys\[\], unsigned int count)

*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.*

**Parameters**

*type type of keys to be ignored* \
 *keys array of keys to be ignored* \
 *count number of keys*

### int BRLAPI\_STDCALL brlapi\_readKey (int wait, 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.*

**Parameters**

*wait 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.*

### int BRLAPI\_STDCALL brlapi\_readKeyWithTimeout (int timeout\_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*

**Parameters**

*timeout\_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.*

## Author

*Generated automatically by Doxygen for BrlAPI from the source code.*
