To download NI software, including the products shown below, visit ni.com/downloads.
Simulating key strokes can be a useful tool. Many tasks can be automated this way ranging from automatically writing a string to an indicator to filling out web forms programmatically by tabbing through and filling in fields. This example includes low level VIs called KeyDown, KeyUp and KeyPress that correspond to those events.
KeyDown and KeyUp are useful for "holding" a key down while others are typed, for example "Shift". KeyPress simply uses KeyDown then KeyUp and is useful for simulating typing, for example alphabetical characters. These three low level VIs all leverage the Windows keybd_event function in the user32.dll by calling a Shared Library Node with different configurations basd on the "keybd_event" function parameters.
Also included is a higher level VI called TypeCharacters. This VI takes as input a cluster that allows the user to pass in an array of keys to press along with the desired action and a delay. Using this VI, it is easy to design a series of key presses that accomplishes your goal.
LabVIEW 2012 (or compatible)
Steps to Implement or Execute Code:
Key Strokes Simulation.vi should run without any further configuration. By default, it types the string "Hello". You can alter this by changing the control cluster labeled Key Array.
Additional Information or References:
Front Panel of Key Strokes Simulate.vi
Block Diagram of Key Strokes Simulate.vi
Block Diagram of Type Characters.vi
**This document has been updated to meet the current required format for the NI Code Exchange. **
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.