10-05-2010 11:56 AM
Is it possible to have a "Key Repeat?" event or something similart that can scan for two keys being held down simultaneously?
Obviously the Key Repeat? event won't cut it because it can only see the last key that went down.
So, is it possible for LabVIEW to detect two keys being held down?
For instance the right-arrow and the top-arrow both held down simultaneously.
Thanks,
R
10-05-2010 12:16 PM - edited 10-05-2010 12:17 PM
Try something like this. Modify as needed. (Attached VI is in 8.0. snippet in 2010)
10-05-2010 12:24 PM
Another option is using the input VIs, but that requires polling.
10-05-2010 08:08 PM
Thanks guys,
I will try that and post how it went. It will be tomorrow before I get back to it.
10-06-2010 01:19 PM
Unfortunately, I cannot post the code.
However, I can post a section of it, see below.
The event for simultaneous keys would have to take care of both events within that event frame.
I di notice that on one PC, the behavior was slightly different than the faster development PC.
The dev PC would only handle the last key that made it down.
On the slower PC, it handles both, but in an erratic fashion.
In my case, I was using scan code.
Actually, I just tried it again as I wanted to confirm what appeared in the key indicator.
I observed a different behavior. If I hit the keys at precisely the same time, it seems to work well.
I will have to try again on the other PC tonight.
Interesting...
Might be okay 😉
Thanks
10-06-2010 01:28 PM - edited 10-06-2010 01:30 PM
Ray,
Don't you need to handle all the possible cases? Key 1 down then Key 2 down. Key 2 down then Key 1 down. Both keys down simultaneously (where simultaneously means within 1 keyboard scan period). And the reverse combinations when one or both keys go up.
edit: What do the keyboard and the OS actually do for multiple keys when both are not meta-keys? end edit
When people push multiple keys they often do so sequentially even if they only want the simultaneous result.
I do not have any code to offer, just more things to worry about!
Lynn
10-06-2010 02:24 PM
I don't think you can reliably capture a true simultaneous key press. It does not exist.
My code looks at either key and acts accordingly if the "other" key is still down (via the booleans stats).
10-06-2010 02:41 PM
Lynn,
Actually, there are cases for single keys being pressed and cases for single keys being held.
The request is to have both keys held down and the software react accordingly.
I guess I've been lucky to get both keys down within a keyboard scan cycle (this PC was running really slow... I mean r-e-a-l-l-y slow).
That's why I need to try it on the other PC.
Christian,
Thanks. Actually, I've got LV2K9, so I did not copy the snippet. I will implement the solution tonight. I was just doing a preliminary experiment on the code while waiting for code to complile.. 😉
As long as both events (for each of the 2 keys) are handled, it may not be necessary to have a seperate event case for the combo of keys pressed. Or... Is that the only way to get around constraints that I'm notaware of, yet..
More later tonight..
🙂
10-06-2010 02:42 PM
@tst wrote:
Another option is using the input VIs, but that requires polling.
They have a main VI which is the UI for the code. I'm adapting this to existing code, so I do not know if creating an input VI (sub-VI?) would work. Maybe I did not understand.
10-06-2010 03:12 PM
LV has a pallete of input VIs, one of which is a VI which returns all the keys currently pressed on the keyboard. The only problem with it is that you have to poll. You can easily run this as a parallel polling loop and transfer the "click" to the main GUI loop using a user event (i.e. when the polling loop reconizes that both keys are pressed and they weren't before, it triggers the event).