From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Using the LabVIEW Key Down Event

Code and Documents

Attachment

This VI shows how to use the Event structure with the Key Down event to determine keyboard selections the user makes, including modifiers. The VI waits on keyboard input from the user. The Key Down event detects the key the user presses and if the user pressed the Alt, Ctrl, or Shift keys.

In this example, if the key the user presses is an ASCII character, indicated by the value of the VKey output, the VI converts the value into a string and displays it. To illustrate the use of the modifier keys, press Ctrl+Shift+Q to stop the VI.

This VI also shows how to discard events. If the Discard Event Boolean control is TRUE, LabVIEW detects Key Down events but does not process them. For example, the user cannot type text into a text box. The user interface receives the keystrokes but does not process them.

It is important to notice that the Discard Event Boolean control does not prevent the execution of code based on user input. It applies only to the user interface. If Discard Event Boolean control is TRUE and the user presses the Esc key, which has been assigned to the "Stop" button, the user interface detects it but ignores it. However, the code that checks the key value still executes and stops the VI.

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

Contributors