Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
9 ratings:
 3.33 out of 5   

Programmatically Type Keystrokes in LabVIEW and LabWindows/CVI

Primary Software:
Primary Software Version: 7.1
Primary Software Fixed Version: N/A
Secondary Software: LabVIEW Development Systems>>LabVIEW Professional Development System

I would like to be able to programmatically type keystrokes, such as pressing the control key, in programs such as LabVIEW and LabWindows/CVI. Is this possible?

Yes, it is possible to programmatically type keystrokes in any environment that can call a DLL. This can be done by calling the keybd_event function of the user32.dll. The user32.dll is located in the C:\WINDOWS\system32 directory.

The keybd_event function synthesizes a keystroke. It has the following syntax:

VOID keybd_event( BYTE bVk, BYTE bScan, DWORD dwFlags, PTR dwExtraInfo)

  • bVk is where you specify the key that you want to press. You can specify the key by using the virtual key code. Reference the virtual key codes document in the attachment section. These values can be in the range 1 to 254. Note that the values that are in the Virtual Key Code document are listed in HEX representation.
  • bScan is not used and should be set to zero.
  • dwFlags is used to determine if the key is to be pressed or released. Setting this parameter to '0' presses the key. Setting it to '2' releases the key.
  • dwExtraInfo is not usually used and should be set to zero.
Note: In LabVIEW, the data type U8 is equivalent to BYTE in C++. Also, the LabVIEW data type U32 is equivalent  to DWORD and PTR in C++.
Here is an example of how to use this function:

Pressing the Ctrl Key: keybd_event (0x11, 0, 0, 0)
Releasing the Ctrl Key: keybd_event (0x11, 0, 2, 0)

Note: The attached document contains a list of virtual key codes.

Related Links:
External Link: MSDN: keybd_event Function()



Report Date: 03/01/2005
Last Updated: 09/17/2013
Document ID: 3J0BMR1J

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit