Admin Production ni-theme
Current Publication

FakeKeystroke

LabWindows/CVI

FakeKeystroke

int FakeKeystroke (int keyCode);

Purpose

Simulates a keystroke by posting a keystroke event to the currently active panel.

This function has the same effect as actually pressing a key at the keyboard.

Note   The order in which you receive the keystroke event in relation to other events is not defined, so you must use FakeKeystroke with care.
Note   If you want to send a fake keystroke consisting of a dual-byte characterdual-byte character, you must call this function twice. First you must pass it the lead byte of the dual-byte character, in place of the ASCII character; then you must pass it the trail byte, also in place of the ASCII character. You cannot use a virtual key code on either call.

Parameters

Input
Name Type Description
keyCode int 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
VAL_POPUP_MENUBAR_VKEY = 0x2500
VAL_POPUP_MENU_VKEY = 0x2700

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

Return Value

Name Type Description
status int Return value indicating whether the function was successful. A negative number indicates that an error occurred.

Additional Information

Library: User Interface Library

Include file: userint.h

LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later

Example

Refer to userint\gridview.cws for an example of using the FakeKeystroke function.