Next: , Previous: Terminal Capabilities, Up: Components of a Curses Interface   [Contents][Index]

2.2 Keyboards and Keys

When a key is pressed, one or more bytes are sent to the program by the keyboard driver. These bytes need to be converted by the program back into a key name. For ASCII characters, this conversion is trivial. A key press of c usually sends the ASCII encoding 142 (c) which can be understood to mean the letter “c”. For other keys on the keypad, like F1 or HOME, the encoding can take multiple bytes and can differ from terminal to terminal. On some terminals, for example, pressing F1 is the same as if the user had typed ESC O P.

The terminfo database provides information that helps associate multibyte codes to keys on the keypad, and there are curses functions that will do the association.