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 ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

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

 

Description

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.

 

Requirements

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

 

 

Mark
NI App Software R&D

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