LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

testing if one key of the keyboard is pressed

Solved!
Go to solution

Hi everyone,

 

As is montionned in the subject, i want to test if a specefic key of the keyboard is pressed, for example i want to know if the key "A" is pressed or "Z" or "3" ?? 

can anyone help with this please

 

Best regards

0 Kudos
Message 1 of 7
(4,456 Views)
Solution
Accepted by topic author Brainiac91

Use an event structure, similar to this. 

 

Example_VI_BD.png

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 2 of 7
(4,440 Views)

Option 1: 

Labview event structure, register event for This VI -> Key down. Then check by ascii code.

Option 2: 

Check  keyboard using Connectivity -> Input device control > Initialize keyboard function and Acquire input data function.

I use 2 if I need to check once, or to verify button is still pressed, because event is registered for VI, so if it is not in focus, it will skip it.

0 Kudos
Message 3 of 7
(4,436 Views)

thks aputman for the solution it works perfectelly, but there is a little issue, i want that the booleen turns to false when i release the key, or it turns automatically to false after a bit of time, is that possible ??

0 Kudos
Message 4 of 7
(4,391 Views)

Hi Brainiac,

 

did you play a little bit with this event structure?

Did you notice the "key release" event?

 

Simple pseudocode:

ON EVENT(key release) DO boolean := FALSE

  

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 7
(4,382 Views)

Hi 

In fact it is my first time using the event structure, but i found a soluion for the problem, it can be handled with the timeout event, thnks for answering anyway 😉

0 Kudos
Message 6 of 7
(4,377 Views)

I wouldn't recommend putting the key up detection in the timeout case.  What happens if you decide you want to make the timeout longer for some reason?  There is a specific event, as Gerd suggested, for detecting when the key is released.  Use it.

Example_VI_BD.png

 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 7 of 7
(4,342 Views)