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

We appreciate your patience as we improve our online experience.

Example Code

Toggle Boolean Button with the Space Bar Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit


  • LabVIEW

Code and Documents



This VI toggles the Boolean button when the space bar pressed, unless the user is entering text into the String Control



This VI demonstrates how an event structure can be used to toggle the value of a Boolean button.The Toggle Key Binding property node can also be used to accomplish this, but the property node cannot be used with every key on the keyboard. In this example we want to toggle the Boolean button with the space bar, which cannot be used with the Toggle Key Binding property node.

Because we do not want the Boolean button to toggle when we are typing in the string control, the Key Focus property node is used to determine if the string control has key focus. If it does have focus, we do not toggle the Boolean control.



LabVIEW 2012 or compatible


Steps to Implement or Execute Code

  1. Run the VI
  2. Press the space bar, and notice the Boolean button toggles
  3. Enter a string to the string control. Then press the spacebar, and notice that the boolean button isn't toggling

Additional Information or References

VI Block DiagramToggle Boolean Button with the Spacebar LV2012 NI Verified BD.jpg



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



NI App Software R&D

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