Recording Key Events

The process of getting input from the keyboard is different under different operating systems. Vermont Views has two routines that can return information about key events: ki(), which reads a keystroke directly from the keyboard, and evnt_get(), which gets a keystroke event. The differences between these two routines will be explained later in this chapter. However, both routines account for the differences in keyboard input under different operating systems, so that your code can be completely portable from one operating system to another. To account for these differences, the keycodes for many keys have been #defined with standard mnemonic key names.

Keyboard Processing Under PCDOS

When the user presses a physical key on an IBM PC or compatible, the ROM BIOS translates the keystroke into a numeric value, a , and places it in the . On the IBM PC and compatibles, a keycode can represent a single key that the user pressed, or a key pressed simultaneously with one or more , such as the Shift, Ctrl, or Alt keys. When a key is pressed in conjunction with a key modifier, the key returns a different keycode. For instance, the function key F1 generates a Vermont Views keycode of KEY_F1, but Ctrl-F1 (the control key and the F1 function key pressed simultaneously) generates a keycode of KEY_CF1. The Caps Lock and Num Lock keys also act as key modifiers. When one of these locks is active, the keycode generated for a particular key may be modified.

The IBM PC has two sets of keycodes, standard keycodes and extended keycodes. Standard keycodes have values from 0 through 255. These keycodes correspond to the standard ASCII characters and a special set of international alphabetic characters, graphic characters, and mathematical symbols.

Extended keycodes have values from 3 to 166. The ROM BIOS indicates that these keycodes are extended keycodes by setting an extra switch. Keys that return extended keycodes belong mainly to a few groups: function keys, cursor pad keys, and function and cursor pad keys pressed simultaneously with Alt or Ctrl.

The keyboard functions of Vermont Views return both standard and extended codes in the same variable. To differentiate between them, Vermont Views adds 256 to the value returned for an extended key code. Thus, extended codes are returned as values greater than 256 and standard codes as values between 1 and 256.

Keyboard Processing Under UNIX, POSIX and VMS

On IBM PC systems, one keystroke generally translates into one keycode that goes in the keyboard buffer. Under UNIX, POSIX and VMS, the keyboard input is read by the system and placed in an input buffer. Vermont Views reads this buffer and returns the keycode associated with the character in the buffer. However, terminal-based systems can also generate one keycode for a keystroke sequence, a series of keys pressed by the user or a series of characters generated by pressing one key. Vermont Views handles this possibility by using the #defined mnemonic key names. When ki() and evnt_get() read from the input buffer, they return the mnemonic key name for the key or keystroke sequence pressed by the user.

As an example, on a VT100 terminal which has no F5 key, the user presses Esc then 5 to simulate pressing the function key F5 on an IBM PC keyboard. The Vermont Views input routines translate the two keystrokes received into a single keycode.

The keystroke sequences and how they are tranlsated to keycodes are determined by the command strings in the vvtermcap entry for the terminal. Vermont Views provides default keystroke sequences for all the keycodes used in the interactive Vermont Views processes (processing data forms, processing menus and choice lists, viewing memory files, viewing files through the help system, and dragging a window). You can change the keystroke sequences associated with a keycode by modifying vvtermcap. See Chapter 58, "Modifying the Terminal Interface," for more information.

Standard Key Names

The keycodes returned by any particular physical key have been standardized for all keyboards. This means that in the Vermont Views system, pressing F1 always returns KEY_F1, whether the user is using a IBM PC keyboard, IBM Extended Keyboard, or a keyboard attached to a terminal running in the UNIX or VMS environment. It also means that the keycode returned by pressing F5 on the IBM PC and the keycode returned by simulating the F5 function key by pressing Esc and then 5 on the VT100 will be the same, KEY_F5.

For convenience, the keycodes for some IBM PC standard keycodes and all the extended keycodes have been #defined with mnemonic key names. For example, the keycode returned by F10 is #defined as KEY_F10. These keycodes are #defined in the vv_key.h header file.


Home Contents Previous Next