Virus scan in progress. Please wait to download attachments.
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.
Download the attached folder and Unzip it to your computer.
Open "Key Strokes Simulation.vi"
Enter the keys in the Key Array control. It is what defines which keys are pressed and for how long. Note that the shift key is pushed down and up in separate steps and that the alphabetical keys are pressed. This is equivalent to holding the shift key down while pressing 'H', the result being an uppercase 'H'.
Run this VI and 'Hello' will be programmatically typed in the Output box.
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.