LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with Key Down event

Hello LabVIEW and National Instruments society,

I'm about to finish my  Electrical Engineering degree .

for my final project i'm building an "RC" car with many applications,

The way I will control it is by using an LabVIEW panel , 

I want to control my car using keyboard using "WASD" keys for movement and other keys for the bonus applications , 

so far I build this Control Panel ,

לכידה.PNG

 

The problem with this vi , is that as I press a curtain key , its saves it the current key and doesnt change untill I press another key , 

the thing i'm aiming for is , that I can "emulate" the Mechanical Action ( from boolean controls) named "Switch Untill Released" ,

so that I can hold the key , press it , and it would only show me the key im pressing only when I'm pressing it ,

My goal would be to reach the functionality seen in the "keyPressState.vi" I attached.

thanks alot for any helpers! 

Download All
0 Kudos
Message 1 of 4
(3,228 Views)

You'll have to use the "Key Up" event also to let the program know the user has released the key. Unfortunately, the Key Up event does not have the same nice "Char" terminal on the left side. You'll have to use the "Scan Code" terminal and figure out which scan code corresponds to which keys you want to respond to.

 

See this similar example:

 

http://forums.ni.com/t5/LabVIEW/key-down-in-event-structure/td-p/2193858

 

0 Kudos
Message 2 of 4
(3,204 Views)

A word of advice:

Use the "Cleanup Diagram" button on the block diagram to make it at least readable.  You wouldn't write C code with random indents, would you?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 4
(3,180 Views)

When talking about applications like this, where you expect the user to press buttons the most time, i wouldn't go for event based programming at all. Reason: Event based programming gives you advantages if interaction is "rare" and "sporadic"; in your case, user interaction takes place very often (as it emulates a remote control device for an RC car i understood) and for a long time without disruption.

Hence, in most of the execution time, your event based approach is more or less an untimed polling architecture nevertheless.

 

So go for the approach you already posted with querying the keyboard state in a polling loop and use a reasonable polling rate (50-100ms is often suitable).

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 4 of 4
(3,165 Views)