Reading the Keyboard Buffer

Naming Tip: Functions that deal with keyboard input contain the abbreviation "ki."

The basic Vermont Views function for reading the keyboard is the keyboard input function, ki():

int ki()

Function ki() will remove a keycode from the keyboard buffer and return its value each time it is called. If no keycode is in the buffer when it first looks, ki() will wait until one is entered. Under UNIX and VMS, ki() makes sure that the keycode read is not the first character in a keystroke sequence. If it is, steps are taken to attempt to translate the keystrokes into one keycode. (See the ki() function reference page in the Function Reference if you are interested in knowing more about the translation algorithm.)

Because ki() waits until a keycode is found in the keyboard buffer, you can create a user-controlled pause in a program by using ki(), as illustrated in the following code fragment.

WINDOWPTR wnp;



v_stpl(0, 0, "Type any key to proceed", wnp);

csr_plwn(wnp);

ki();

The message is written on the first line of the full screen window, the physical cursor is placed after the message, and a call is made to read the keyboard. The program will halt until a key is pressed.

Warning: ki() does not check the event queue for mouse events. Under PCDOS, the user can fill the event queue with mouse events while ki() is waiting for a keystroke. If you need to check for both mouse and keyboard events, use evnt_get() instead of ki().

More:

Checking the Keyboard Buffer

Checking the Last Keycode Read

Checking the Status of Key Modifiers (PCDOS and OS/2)


Home Contents Previous Next