Showing results for 
Search instead for 
Did you mean: 

Simultaneous keys for "Key Repeat?" event

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.





0 Kudos
Message 1 of 11

Try something like this. Modify as needed. (Attached VI is in 8.0. snippet in 2010)


Download All
Message 2 of 11

Another option is using the input VIs, but that requires polling.

Try to take over the world!
0 Kudos
Message 3 of 11

Thanks guys,


I will try that and post how it went.  It will be tomorrow before I get back to it.

0 Kudos
Message 4 of 11

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.




Might be okay 😉






0 Kudos
Message 5 of 11



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!



Message 6 of 11

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

Message 7 of 11



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.




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




0 Kudos
Message 8 of 11


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


0 Kudos
Message 9 of 11

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

Try to take over the world!
Message 10 of 11