2.3 Getkey

Getkey reads key strokes from standard input or the console if TERM is not set, and returns an integer representing the key that was pressed in a manner similar to the getchar function in the standard I/O library. If an ASCII character key is pressed, getkey returns the ASCII integer equivalent of that character. When an arrow key or other special function key is pressed, getkey translates the escape sequence sent by the terminal into an integer that represents the key pressed. For example, most terminals send a sequence of characters when the down arrow key is pushed. Getkey translates that sequence of characters into the constant CURDOWN. Getkey translates multi-character special key sequences into a single integer that is returned.

The constants returned by getkey are defined in the include file <cbase\escape.h>, and are in the range of 256 to 511. Getkey uses the escape sequences in the terminal definition to translate the escape sequences received into the corresponding integer. If an escape sequence that was not defined in the terminal definition is read by getkey, the escape sequence will be passed to the calling program unchanged, one character at a time. In general, the function of getkey is to return an integer each time one key is pressed on the terminal keyboard.