LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Keyboard

I want to record and save the keys pressed during my program but the output from the keyboard icon I'm using is only a single piece of informaiton and it changes back to the default as soon as the key is no longer being pressed. The output says it should be an array of enums (I also don't understand exactly what enums are) however I'm just getting one number. Very frustrating - any help or advice would be greatly appreciated.
0 Kudos
Message 1 of 3
(3,354 Views)


AussieClaire a écrit:
I want to record and save the keys pressed during my program but the output from the keyboard icon I'm using is only a single piece of informaiton and it changes back to the default as soon as the key is no longer being pressed. The output says it should be an array of enums (I also don't understand exactly what enums are) however I'm just getting one number. Very frustrating - any help or advice would be greatly appreciated.


The keyboard vi do exactly what is said : returns the value of the key(s) which are pressed at the moment you call the vi. When you press more than one key at a time (up to 4- 6 depending of the key type) , you get a sorted array of their values. An enum is a special numeric control or indicator that accept only a predefined set of values.

To record the keys pressed during execution, you need to store them in an array : each time a new key-press is detected, append it to the previous values. If you need to record more than a few thousand of keypress, initialize a pre-sized array, and replace elements instead of appending them.

Chilly Charly    (aka CC)
Message 2 of 3
(3,344 Views)

Also, if you only want to monitor keys pressed when your VI has focus, you can use an event structure with the Key Down event for the VI. When you put this in a loop, it will recognize every time you click the key and return it through the event terminals. You won't have to deal with recognizing when you released keys and so on. It doesn't return an array though, so it will miss keys if you press them at the exact same moment. You can find tutorials on using events on this site.

To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).


___________________
Try to take over the world!
Message 3 of 3
(3,337 Views)