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

Use Filter Events to Handle Keyboard Input for Boolean Controls

Code and Documents

Attachment

Overview
This example VI show a way to use Filter Events to discard key presses for any key except Return.

 


Description
If you have key focus on a Boolean control on the front panel, you can use the following keys to toggle the Boolean state:

1)Return or Enter

2)Space

3)T/F

4)1/0

5)+/-

There is no way to disable these standard keyboard actions, so if the UI requires that only the Return key can toggle a Boolean control, you must find a workaround. This example shows how you can use Filter Events to discard key presses for any key except Return.

 


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Download the attached folder to your computer
  2. Open the VI "Filter Event Boolean 2012 NIVerified.vi"
  3. Run the program
  4. Set the "Desired VKey" to "Return"
  5. The VI automatically puts key focus on the "OK Button" Boolean control. Any key you press will update the "VKey" and "Character" indicators with the key's character type and character number, respectively.
  6. Notice that the "OK Button" control does not respond to any key but Return

 

Additional Information or References
VI Block Diagram

 Block Diagram.png

 

 **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.