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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Detect 2 Push Button Control Key Presses SImultaneously

I am using a touchscreen PC.  I tell the user to touch 2 push button controls on the front panel at the same time.  What is the best way to detect that both buttons were pressed simultaneously?  Thanks!

0 Kudos
Message 1 of 8
(4,520 Views)

Change button actions to switch untill released.

Register one event for both buttons value change.

Check both buttons are true (AND)

Message 2 of 8
(4,505 Views)

With computers, there is no such things are simultaneously, the presses are most likely milliseconds apart (which is an eternity in computer terms).

 

How do you detect a single push? What is the mechanical action? Can you show us some code?

 

You can handle both button value changes in a single event case containing the two terminals. For each trigger of the event, do an AND of the two buttons. If the result is true, both buttons are down.

Message 3 of 8
(4,495 Views)

Altenbach,

 

The mechanical action I am using is "Switch When Pressed: for both buttons.  I wrap a while loop around an event structure with an event for both buttons and have an AND in that case.  If both were pressed then the AND will become true and stop the while loop.  The method works if I press button 1 and then button 2.  The code actually runs twice though the event case to catch both key presses.

 

I'm not sure if there is a better way.  If you know of any, please enlighten me.  I've attached my code.  Thanks!

 

0 Kudos
Message 4 of 8
(4,473 Views)

@testdesign wrote:

Altenbach,

 

The mechanical action I am using is "Switch When Pressed: for both buttons.  I wrap a while loop around an event structure with an event for both buttons and have an AND in that case.  If both were pressed then the AND will become true and stop the while loop.  The method works if I press button 1 and then button 2.  The code actually runs twice though the event case to catch both key presses.

 

I'm not sure if there is a better way.  If you know of any, please enlighten me.  I've attached my code.  Thanks!

 


You probably do want a switch until released action (darned USERS are slow and poorly coordinated.)  Now this comes with some additional stuff you need to account for:  Like you will get an event for each button press and each button release.  That simple AND of the button values is the correct filter to determine that both keys have been activated.


"Should be" isn't "Is" -Jay
Message 5 of 8
(4,468 Views)

testdesign wrote: 

I'm not sure if there is a better way.  If you know of any, please enlighten me.  I've attached my code.  Thanks!


You can delete the timeout event, it is not needed.

You can delete the 10ms wait, it serves no purpose.

 

Yes, the event will fire twice, once for each button press, but you read the current values of both terminals inside the event. Nothing wrong with that.

 

I am not sure about the mechanical action, but I think "switch" (what you have now) is better than "switch until released". With the switch until released, the code cannot be operated on a mouse-driven interface (you can only hold down one button at any given time!). However, if the buttons are switch action, you need to ensure that they are reset to false when the program starts.

Message 6 of 8
(4,450 Views)

@CA you are quite right that a mouse driven interface could not test that code with wsitch until released but, that is not the target hardware!  Without knowing exactly what touchpanel or, having one to play with, I cannot determine if two touches can be registered.  I know on my phone multiple touches are permitted (or zoom wouldn't work.)  The OP will need to integrate the system in situ to determine best method


"Should be" isn't "Is" -Jay
Message 7 of 8
(4,444 Views)

You can use timeout to push buttons back after specified time.

This way it will work both on touchscreens and set security on mouse ones. See vi, buttons have latch when pressed action.

Message 8 of 8
(4,424 Views)