LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to I trigger an event based on the status of a pushbutton?

Solved!
Go to solution

@JHourigan wrote:

If I want to simply detect a button push event. I set the mechanical action of the boolean button to switch-until-released. Then I use the mouse down event structure on that button to detect the event.  It avoids having to include a case structure logic to address the state of the boolean in an Value Change event structure. The button immediately returns to the false condition after release.


You need to re-read the first post.  The OP wants to run something as long as the button is ON.  This calls for a mechanical action of switch when pressed or released.  He doesn't want to be holding the mouse down while his code runs.  Click once, ON.  Click again, OFF.

 

Your method is similar to using a latch when pressed/released and a value change event.  When the event fires, the button is read, and it goes back to its original state automatically.  There is no need to use a case structure to determine the state of the button.  The event gets fired and that is all that counts.  If you needed to perform different actions depending upon the button state, you would not use a latch type.  You would use a switch type, which is what the OP wants.

 

However, I like your solution whenever I need to use a local variable or a reference of the button since either of these cannot be used with a latch type switch.  In this case, using a switch until released and a mouse down (or up) event would work fine.  I prefer mouse up because if you make a mistake and catch it while still holding the mouse button down, you can move the mouse away from the switch and release the button, and no event occurs.  Same for switch/latch when released.

- tbob

Inventor of the WORM Global
0 Kudos
Message 11 of 13
(452 Views)

Yes...I shanked in reading the original post. Tbob's use of mouse up is clever...particularly given my propensity to not pay attention. 

0 Kudos
Message 12 of 13
(444 Views)
0 Kudos
Message 13 of 13
(25 Views)