# GetKey

GetKey (void);

## Purpose

Waits for the user to press a key and then returns the key code as an integer value.

If the user has already pressed a key, the key value is returned immediately.

| Note GetKey detects keystrokes only in the Standard I/O window or in the console window of a Windows console application. GetKey does not detect keystrokes in windows you create with the User Interface Library. Linux GetKey detects keystrokes only in the Standard I/O window. You must first call the SetStdioPort function to specify to use the Standard I/O window.

The values GetKey returns are the same as the key values the User Interface Library uses. Refer to userint.h. The following table shows examples of keystrokes and the values GetKey returns for them.

Example Keystrokes and GetKey Return Values

Keystroke | Return Value
<b> | 'b'
<Ctrl-b> | (VAL_MENUKEY_MODIFIER | 'B')
<F4> | VAL_F4_VKEY
<Shift-F4> | (VAL_SHIFT_MODIFIER | VAL_F4_VKEY)

### Example

/* Give the user a chance to quit the program. */
int k;
FmtOut ("Enter 'q' to quit, any other key to continue");
k = GetKey ();
if ((k == 0x0051) || (k == 0x0071)) /* q or Q */

exit (0);

## Parameters

None.

## Return Value

Name | Type | Description
result | integer | The value representing the key pressed by the user. Key codes can be formed by either an ASCII character, a virtual key, or by a logical OR operation on values representing a modifier key and either an ASCII character or a virtual key. A modifier key is a <Shift> key, <Alt> key, or <Ctrl> key. The following constants represent the modifier key: VAL_SHIFT_MODIFIER VAL_UNDERLINE_MODIFIER VAL_MENUKEY_MODIFIER VAL_SHIFT_AND_MENUKEY ASCII characters are represented by a literal character, for example, 'A' or 'D'. Multibyte characters are returned as two consecutive key codes. The first key code represents the lead byte while the second key code is the trail byte of the multibyte character. As a result you have to call GetKey twice in a multibyte setting to obtain the entire multibyte character. Virtual keys are non-ASCII keys represented by the following key codes: VAL_FWD_DELETE_VKEY VAL_BACKSPACE_VKEY VAL_ESC_VKEY VAL_TAB_VKEY VAL_ENTER_VKEY VAL_UP_ARROW_VKEY VAL_DOWN_ARROW_VKEY VAL_LEFT_ARROW_VKEY VAL_RIGHT_ARROW_VKEY VAL_INSERT_VKEY VAL_HOME_VKEY VAL_END_VKEY VAL_PAGE_UP_VKEY VAL_PAGE_DOWN_VKEY VAL_F1_VKEY VAL_F2_VKEY VAL_F3_VKEY VAL_F4_VKEY VAL_F5_VKEY VAL_F6_VKEY VAL_F7_VKEY VAL_F8_VKEY VAL_F9_VKEY VAL_F10_VKEY VAL_F11_VKEY VAL_F12_VKEY
| Note To use these define constants, you must include userint.h in your program.
When the VAL_MENUKEY_MODIFIER is used in conjunction with a letter, the letter is always represented in its uppercase form.