LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Capture keystrokes

Hi I am trying to use this program in the lab, to capture each pressed key. Could someone help me take a look and the to improve it?

 

Please just try typing the phrase:  Anniversary is Commemoration and Celebration

 

It is giving me a lot of space between letters

shift and any character is giving me that character twice

Fast typing is omitting some characters...

 

Thanks for any help.

 

 

0 Kudos
Message 1 of 8
(2,414 Views)

hi agyna,

 

I think a much better way to implement this will be with an event structure.  If you drop an event structure and add an event about <THIS VI> and make it a key down event, you will be able to capture every key press.  This will be much better than timing and using the keyboard input VIs that you have now.  This example shows the basics of what I am talking about.

 

http://zone.ni.com/devzone/cda/epd/p/id/3924

 

Ryan

Applications Engineer
National Instruments
0 Kudos
Message 2 of 8
(2,388 Views)

I tried this, it works fine. But the problem is that this works only if I am typing in this front panel. Once I open word and start typing in word or wordpad, it doesn't work. I think it is focused on the front panel only.

 

Could you help improve this such that I can type my text in a word page and the get the characteres captured?

We will be using another program to enter the text, we cannot use the front panel to enter the text.

 

Thank you.

0 Kudos
Message 3 of 8
(2,356 Views)

Hi,

 

Event structures won't register the key strokes when other programs are in focus. I made a fun little example of how to log key strokes using the keyboard VIs. I did a producer/consumer so that you don't miss keystrokes and I only enqueue when a new key is pressed or released. I think it works pretty well. Take a look at it and play around to see how it works. The next step is to convert the enum array to strings so that you can actually log the keystrokes, but that lookup table was a bit more complicated to make Smiley Wink so I will leave that up to you if this is what you want to use. I have attached a version saved in LabVIEW 8.0 for those who can't open it in 2011.

 

Key Logger.png

 

Let me know if that helps!

0 Kudos
Message 4 of 8
(2,339 Views)

I quickly modified the above code so that it converts the enum to a string and shows the text.

 

Key Logger_string.png

 

 

0 Kudos
Message 5 of 8
(2,334 Views)

Can you please post this as attachment? So I can open it easily. I cannot drag this from the forum page to the block diagram.

 

Thanks.

0 Kudos
Message 6 of 8
(2,317 Views)

Also the CPU usage is very high, making the system slow. Any Idea how to reduce it?

0 Kudos
Message 7 of 8
(2,309 Views)

The CPU usage is very high because the top loop does not have any timing, it is running as fast as it can to make sure it does not miss any keystrokes. You can add a Wait in the top loop to release the processor, even if you wire a constant of 0 to the wait, it will at least release the processor between loops. I am not on the computer that has that program on it, but I would recommend saving the image to your computer and then dragging it to your block diagram. A lot of browsers don't let you drag snippets directly into LabVIEW.

 

Regards,

0 Kudos
Message 8 of 8
(2,298 Views)