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

If NULL or '' was given to brlapi_enterTtyMode(), a brltty command is returned, as described in <brltty/brldefs.h> . 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 some driver name was given to brlapi_enterTtyMode(), a raw keycode is returned, as specified by the terminal 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() 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, brlapi_readKey() will return -1, brlapi_errno will be BRLAPI_ERROR_LIBCERR and errno will be EINTR.