LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any way to read from the Windows keyboard buffer directly?

Does anyone know a way to read keyboard input without having to use a LabVIEW input "control" (usually with the "key focus" attribute)?
 
Ideally, I would like to be able to read from the keyboard (Windows XP) in the same way that I would read from a device such as a serial port, i.e the system might maintain an input buffer which could be read from, flushed, and status interrogated?
 
Anyone able to help - thanks.
 
Mark.
0 Kudos
Message 1 of 4
(5,665 Views)

You can read keyboard clicks without using a string control, but it won't be as simple as a serial read.

First, you can use the VIs in the Advanced>>Input Device palette, which will tell you which button is clicked at any moment. This means you will have to continuously poll and that you could, theoritically, miss some keys.

Second, if you want to capture keystrokes inside the VI, you can use an event structure with the Key Down event. This will gurantee that you get all the clicks and you don't need to poll.

Third, you can probably call some windows API functions to intercept the windows event which is fired when you press a key. Try searching the Microsoft Developer Network (MSDN), which has documentation of the windows API.


___________________
Try to take over the world!
0 Kudos
Message 2 of 4
(5,657 Views)

Thanks - and sorry I've been a bit late to respond.

Maybe a combination of your first two suggestions could do the job, but it looks like a fair bit of carefull programming would be required to get the right behaviour.

For the time being, I think I'll have to stay with reading from a string control.

Regards.

Mark H.

0 Kudos
Message 3 of 4
(5,610 Views)

There is no need to combine the first two methods.

If your VI is the active window (it will be if you use the string control), then the second method (key down event for the VI) is all that you need, and it will work perfectly.

The third option is probably more complex, but may be possible. You can try doing some reading here to see if you can come up with something. You can try searching for something called "LV toolbox", which I believe shows examples of working with windows message queues, Although I'm not sure whether you can intercept messages from other processes.


___________________
Try to take over the world!
0 Kudos
Message 4 of 4
(5,603 Views)