Admin Production ni-theme
Current Publication

EVENT_KEYPRESS

LabWindows/CVI

EVENT_KEYPRESS

Description

When a user presses a key on the keyboard, LabWindows/CVI generates an EVENT_KEYPRESS event and sends the event to the callback function associated with the control that has the input focus and to the callback function associated with the control’s panel. If you swallow the event, LabWindows/CVI does not continue processing the event.

For ANSI panels, if a user enters a dual-byte character in a control, two EVENT_KEYPRESS events are sent to the callback function. To process the character as a single event, 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. Additionally, you can use SetKeyPressEventKey to change the character that the user entered. Do not use SetKeyPressEventKey in the first EVENT_KEYPRESS event of a dual-byte character.

For UTF-8 panels, a single EVENT_KEYPRESS event is sent to the callback function per character. Both KeyPressEventIsLeadByte and KeyPressEventIsTrailByte functions return FALSE. You can use GetKeyPressEventCharacter to obtain the UTF-8 character. Additionally, you can use SetKeyPressEventKey to change the character that the user entered.

Note Note  UTF-8 panels are only compatible with LabWindows/CVI 2020 and later.

Applies To

ActiveX controls, binary switches, canvases, color numerics, command buttons, graphs, LEDs, list boxes, numeric slides, numerics, panels, picture buttons, picture rings, radio buttons, ring slides, rings, splitters, strings, tables, tabs, text boxes, text buttons, toggle buttons, and trees

Event Data Parameters

eventData1 = key code

Note Note  For UTF-8 panels, the key code returned in eventData1 is a Unicode key code. This Unicode key code is packed, and you must unpack it using the UnpackKeyCodeUnicode function.

eventData2 = Value to pass to the following functions: KeyPressEventIsLeadByte, KeyPressEventIsTrailByte, GetKeyPressEventVirtualKey, GetKeyPressEventCharacter, GetKeyPressEventModifiers, and SetKeyPressEventKey.

Refer to the KeyCallback function in the samples\userint\multikey.cws sample program for an example of a callback that uses these functions.

Key Codes

For ANSI panels, key codes are formed by a logical OR operation on values representing a modifier key and either an ASCII character or a virtual key.

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.

For UTF-8 panels, key codes are Unicode key codes. Unicode key codes are formed by packing a Unicode code point, virtual key, and modifier. You must unpack Unicode key codes into the individual values representing these three elements using the UnpackKeyCodeUnicode function.

The Unicode code point can represent any character.

A modifier key is a <Shift> key, <Alt> key, or menu modifier key (<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

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

You cannot use ASCII with a virtual key code. You can use virtual key codes with or without a modifier, and you can use the shift and menu modifier keys 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

LabWindows/CVI Compatibility

LabWindows/CVI 3.0 and later.