LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

key down in event structure

Solved!
Go to solution

key down in event structure

Hello

I am using arrows on my keyboard to controll program (UP DOWN LEFT RIGHT)

By using key down in event structure i know what button is pressed

But I need  to detect that 2 buttons are pressed in the same time to make diffrent cases for that. I dont know haw to handle that.

Any suggestions appreciated

0 Kudos
Message 1 of 13
(6,399 Views)
Solution
Accepted by topic author pawhan11
08-27-2015 04:09 PM

Re: key down in event structure

Keep an array of four booleans in a shift register, then turn each element on or off depending on key press or key release events. The number of true booleans will tell you the state of all buttons at all times.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 2 of 13
(6,391 Views)

Re: key down in event structure

So simple Smiley Very Happy

Big thanks

 

0 Kudos
Message 3 of 13
(6,384 Views)

Re: key down in event structure

Here's what I had in mind. Modify as needed.

 


LabVIEW Champion Do more with less code and in less time
Message 4 of 13
(6,381 Views)

Re: key down in event structure

Sorry altenbach for digging this old thread again.
-The code which you gave works for all 2 key combinations.
-Tried for three key combinations (i didn't know whether it will also come into same category or not) Luckily most key combinations worked.
-Except which involves Left-Up-Down key events. all these combinations failed.
-Strangely i didn't get any scan code in these specific events for third button press.
-Any thought on this?
Thanks
uday
0 Kudos
Message 5 of 13
(6,076 Views)

Re: key down in event structure


@udka wrote:
Sorry altenbach for digging this old thread again.
-The code which you gave works for all 2 key combinations.
-Tried for three key combinations (i didn't know whether it will also come into same category or not) Luckily most key combinations worked.
-Except which involves Left-Up-Down key events. all these combinations failed.
-Strangely i didn't get any scan code in these specific events for third button press.
-Any thought on this?

Interesting. There must be some deeper limitations somewhere. Not sure if it is LabVIEW or windows. (maybe somebody could try on mac or linux)

 

All two-key combinations work, I can do "up+down+right" and "left+down+right" from all possible three key combinations. All four keys never works.

 

Maybe somebody from NI can comment.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 6 of 13
(6,066 Views)

Re: key down in event structure

-Yes, only Left+Up+Down, Left+Down+Up, Down+Up+Left and Down+Left+Up combinations failed in three key combinations.
Thanks
uday
0 Kudos
Message 7 of 13
(6,061 Views)

Re: key down in event structure

Well, it seems to get more complicated.

 

Under windows 7, things seem to work just fine and I can light up all LEDs at once. The problem only occurs under windows 8. What is your OS.

 

Digging deeper (under windows 7), it seems that the number of possible simultanous down keys is random and between 3 and 6, depending on the keys.

For example, we can hold down in sequence a+s+d+f+g+j, but not a+s+d+f+g+h (the "h" is no longer recognized).

 


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 8 of 13
(6,033 Views)

Re: key down in event structure

OK, this seems to be a limitation of the keyboard hardware and the term is Keyboard Ghosting.

 

See this explanation by mycrosoft.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 9 of 13
(6,019 Views)

Re: key down in event structure

On my Mac (27" iMac with Apple keyborad with numeric keypad and arrow keys), (OS X 10.8.5) and LV 2013 (32-bit) the scan codes are left = 123, right = 124, down = 125, and up = 126. Afer changing the array in altenbach's VI to those values, the VI runs. 

 

All the 2-arrow combinations work. Left+Right+Up and Left+Right+Down work. Up+Down works. No three arrow combination with both Up and Down works and the 4-arrow combination does not work.

 

Running with execution highlighting on (patience, please) shows that the event structure does not fire when the third or fourth key in the non-working combinations is pressed.  This makes me think it may be an OS issue - not generating the interupt for the keypress.

 

Lynn

0 Kudos
Message 10 of 13
(6,013 Views)