LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

getting char form keybaoard

Hi,

 

in attached file, I am trying to get up to 10 characters from the key board. Meaning that each time a key is pressed, I get it, up to a max of 10; and start again.

 

Now the issue I am facing is that it is working ony when, after starting my vi (RUN), I click the mouse on the running Front Panel.

Once the mouse is clicked some where else, or I am typing somewhere else, it is not recording the key.

 

what I want is to open a wordpad page, type some special characters, and so, while typing in my wordpad, my running vi, should be recording those keys.

 

Any help?

0 Kudos
Message 1 of 17
(3,957 Views)

Without looking at the code, I'm guessing you're using the Key Down event to get the click. This only works when you have focus, as you saw.

 

What you can do is use the keyboard VIs (search the palettes), which work without focus as well. Just be aware that you will need to recognize all the changes yourself (you can use a shift register to hold the old value of which buttons which pressed), because the VI just returns which keys are currently pressed.


___________________
Try to take over the world!
0 Kudos
Message 2 of 17
(3,952 Views)

Hi,

 

I would look into using the Initialize Keybaord.vi, Aquire Input Data.vi, and Close Input Device.vi.  These should allow you to monitor the keyboard as you are trying to.  You could possibly do this with an event structure but I would use a producer/consumer loop.  There are examples of using the keyboard vi's and producer/consumer loops in LabVIEW.  Just use the search feature in the labVIEW example finder.  If you are unable to locate a good example just let me know.

 

Regards,

 

Greg H.

Applications Engineer
National Instruments
0 Kudos
Message 3 of 17
(3,930 Views)

So I tried this, but I do I get the pressed key to a file so that I can read what was pressed. It is just disappearing...

 

Thanks for any help.

0 Kudos
Message 4 of 17
(3,909 Views)

Wire the output to a shift register and compare it with the previous value. If it is not equal, build it in to an array or convert it in to string depending on what you want to do with it.

 


CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
0 Kudos
Message 5 of 17
(3,897 Views)

Not really sure that I understand what you mean. could explain a bit more?

 

0 Kudos
Message 6 of 17
(3,871 Views)

The real problem is that the character appear only when the key is pressed. When I release the key, the character disapears immediately, so I cannot record it... or send to a file...

0 Kudos
Message 7 of 17
(3,870 Views)

Try this.

I am not proud of the code but it does the job. Also using a build array inside a loop is not very efficeint. You need to initialise the array outside the loop and replace the subset. You can do that.... Smiley Happy

keyboard.png


CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
0 Kudos
Message 8 of 17
(3,854 Views)

It should be pointed out that the code can be simplified (and that you don't need the for loop anyway):

 

Log_Keys_BD.png

 

Note that this example uses a trick of the AND array elements primitive, where it returns T for an empty array.


___________________
Try to take over the world!
0 Kudos
Message 9 of 17
(3,850 Views)

Hi,

 

While this method of using a build array will work, I would suggest using a producer/consumer loop as well.  Examples of this can be found in the LabVIEW example finder.  Using this setup will make sure that no keystrokes are missed.

 

Regards,

 

Greg H.

Applications Engineer
National Instruments
0 Kudos
Message 10 of 17
(3,845 Views)