Example Code

Programmatically Generate Keyboard Presses

Code and Documents

Attachment

Overview

This VI takes a text input using the string control and converts this to a series of DLL calls which generate key presses that match the input.

 

Description

The VI uses keybd_event in USER32.DLL. It extracts each individual character from the string control and sends the relevant command to the Call DLL Node. Currently it is set only to recognise letters and spaces. It cannot generate key presses such as capital letters (shift+letter) or end of line (return character). However, using the  'Virtual Key' ring constant one could easily modify to include other characters.

 

Requirements

LabVIEW 2012(or compatible)

 

Steps to Execute Code

1.Enter some text in to the string control and run the VI.
2.The amount of time between pressing run and the keypresses being generated canbe altered by changing the wait time in the first frame.
3.After running, switch the open application to one which will accept text (such as notepad) and see the keypresses being generated.

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

Eden S
Applications Engineer
National Instruments UK & Ireland

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.