Example Programs

Showing results for 
Search instead for 
Did you mean: 

Programmatically Simulate Key Strokes in LabVIEW


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)

Windows OS



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.

  1. Download the attached folder and Unzip it to your computer.
  2. Open "Key Strokes Simulation.vi"
  3. 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'.
  4. 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. **

Member Link Butler

I need to simulate the key strokes to input a path-to-file string automatically. For examle: "C:\LabVIEW\longhorn\key_strokes.vi".

I used your code above, but this code doesn't have ASCII code for the characters: ":" colon, "\" back slash, and "_" underscore. Those characters are very important to complete a path-to-file string. I also need to simulate the pressing of Alt button.

Can you modify your code and put those ASCII character into your code?


Member Vi-Shaman


You Genius!... just what ive been trying to do..... A very big help!... I owe you a pint!

Member stubon
Member SULLutions

Just what I needed. Thanks.

And stubon's link was very helpful in customizing to my current application.

...when a single discipline is not enough
Member kdharanya

Hi Link,

How did to manage to simulate "\",":" in labview?

I am facing same problem. I am trying to generate keypresses for a file path.

Kindly help



Member AshKum

Excellent !! This is exactly what i have been looking for.