# EVENT_KEYPRESS

Object Types: Panels, numerics, color numerics, numeric slides, strings, text boxes, command buttons, picture buttons, toggle buttons, text buttons, radio buttons, LEDs, binary switches, rings, ring slides, picture rings, list boxes, graphs, canvases, tables, trees, and tabs.

Description: Keyboard events are sent to the callback function associated with the control which has the input focus, and to the callback function associated with the control’s panel. If you swallow the event, LabWindows/CVI does not process the event any further.

If a user enters a dual-byte character in a control, two EVENT_KEYPRESS events are sent to the callback function. In order to process the character as a single event, you should ignore the first event. You can use KeyPressEventIsLeadByte to determine when you receive the first event of a dual-byte character. When you receive the second event, KeyPressEventIsTrailByte returns TRUE. You can then use GetKeyPressEventCharacter to obtain the full dual-byte character.

Event Data Parameters:

eventData1 = Key code.

eventData2 = Pointer to key code. Pass eventData2 to the following functions: KeyPressEventIsLeadByte, KeyPressEventIsTrailByte, GetKeyPressEventVirtualKey, GetKeyPressEventCharacter, GetKeyPressEventModifiers, and SetKeyPressEventKey.

## Key Codes

Form key codes 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 menu modifier key (the <Ctrl> key). The following constants represent the modifier key.

VAL_SHIFT_MODIFIER = 0x010000
VAL_UNDERLINE_MODIFIER = 0x020000
VAL_MENUKEY_MODIFIER = 0x040000
VAL_SHIFT_AND_MENUKEY = 0x050000

ASCII characters can be represented by a literal character, for example, 'A' or 'D', or an ASCII value. There is no distinction between upper and lower case ASCII characters.

Virtual keys are non-ASCII keys represented by the following key codes:

VAL_FWD_DELETE_VKEY = 0x0100
VAL_BACKSPACE_VKEY = 0x0200
VAL_ESC_VKEY = 0x0300
VAL_TAB_VKEY = 0x0400
VAL_ENTER_VKEY = 0x0500
VAL_UP_ARROW_VKEY = 0x0600
VAL_DOWN_ARROW_VKEY = 0x0700
VAL_LEFT_ARROW_VKEY = 0x0800
VAL_RIGHT_ARROW_VKEY = 0x0900
VAL_INSERT_VKEY = 0x0A00
VAL_HOME_VKEY = 0x0B00
VAL_END_VKEY = 0x0C00
VAL_PAGE_UP_VKEY = 0x0D00
VAL_PAGE_DOWN_VKEY = 0x0E00
VAL_F1_VKEY = 0x0F00
VAL_F2_VKEY = 0x1000
VAL_F3_VKEY = 0x1100
VAL_F4_VKEY = 0x1200
VAL_F5_VKEY = 0x1300
VAL_F6_VKEY = 0x1400
VAL_F7_VKEY = 0x1500
VAL_F8_VKEY = 0x1600
VAL_F9_VKEY = 0x1700
VAL_F10_VKEY = 0x1800
VAL_F11_VKEY = 0x1900
VAL_F12_VKEY = 0x1A00

ASCII cannot be used with a virtual key code. Virtual key codes can be used with or without a modifier. The shift and menu modifier keys can be used together. For example, the expression VAL_MENUKEY_MODIFIER | 'A' specifies <Ctrl-A>. Other valid key codes include the following:

VAL_TAB_VKEY
VAL_SHIFT_MODIFIER | VAL_F5_VKEY

The result of the logical OR operation is a 4-byte integer consisting of three bit fields, 0x00MMVVAA, where

MM = the modifier key
VV = the virtual key
AA = the ASCII key