02-19-2014 03:55 PM
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 ,
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!
02-19-2014 06:00 PM
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
02-20-2014 01:26 AM
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?
02-20-2014 02:09 AM
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