How do I detect two simultaneous button presses? #989
Replies: 2 comments
-
Posted at 2018-07-16 by @gfwilliams Hi! It's basically impossible for you to press both buttons at exactly the same time, so instead you just need to shift thinking a bit - call the same function when either button is pressed, then check the state of both in that function:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-07-17 by @allObjects Just what @gordon says... though: since you never really press them at the same time but have watches on both, you get two events in the event queue... first one is served and you check for both buttons, but you set a flag for the button you just checked so that when its press event will about to be served, you do not count it as a press, but just clear the flag... ;-)... so the code may look like this:
...this is though not the full truth but the truth either... but I let you figure that out yourself... hint: what is when you press BTN1 and hold it... and then 'later' you also press BTN2 - while BTN1 is still held? ...so you may watch both edges as well as define windows where presses are presses and when they are separate ones, even though presses may overlap... Enjoy! PS: Code not tested (yet)... but it is a nice 'problem' to solve! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2018-07-14 by BootySnorkeler
Hi,
How do I detect two simultaneous button presses? I've tried putting a setWatch() inside another setWatch(), but the inner watch still activates even when I don't trigger the outer one. Any tips?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions