LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

programmatic keyboard events

I have a program which needs to interact with another LabVIEW program via programmatically generated keyboard events, that is, there is no user pressing keys, but another program simulating this.  Unfortunately, I do not have access to the code of the other program, only the compiled executable.  The program generates two kinds of keyboard presses: simple, one key ASCII ("C") and modified commands (e.g. "Control + K")  I can recieve the first, but not the second.  The second kind of event appears as if only the "Control" key was pressed, without any other key.

 

I am using an event structure to recieve the events, and I the event returns ASCII character zero.  When I manually press the keys "Ctrl+K", the event is properly processed and PlatMod.Ctrl comes back TRUE and Char returns 107, which I can then use to successfully process the event. 

 

As a separate, perhaps unrelated problem, I have noticed that when I compile my program as an executable, I can only recieve events that occur at the physical keyboard--not even the programmatically generated 'C' keypress will work.

 

I have attached my top level VI.  It isn't terribly pretty, but hopefully it will help.  Apologies to anyone who recognizes the name: I am mimicking another program, one that the program generating the keyboard events knows how to interact with.

0 Kudos
Message 1 of 6
(8,253 Views)

An update: Two vis (attached) reproduce and boil down the behavior I described.  If I use TestRecvKey to observe which keys are pressed on the keyboard, then a "Ctrl+K" will come through fine, illuminating the "Ctrl" boolean indicator and reporting the ASCII code for K.  However, if I use TestSendKey to send a Ctrl+K, only the Ctrl key ever shows up.  It's as if the second key press doesn't exist.  On the keyboard, I can press Control, wait and then press K, the result is the same as a simultaneous push (Ctrl illuminates and ASCII key code is reported correctly.)  In fact, when I use TestSendKey to send ANY two keys, only the first appears to be sent, and not the second.
 
I suspect that this is some sort of timing issue, but playing around with delays between programmatic key presses didn't get me anywhere. 

 

Download All
0 Kudos
Message 2 of 6
(8,206 Views)

First thing that I believe that will be easy id the problem geeting responce from the other program. I believe that this could be that when you are making your exe that you did not select the Pass all command line arguments to application. This should fix the communication problem.

 

Second I believe that you are going to have to keep up with the keys that are press and with the keys that are released even virtually. I updated your code to show an example with the control and shift keys. I hope this helps.

 

Tim
GHSP
0 Kudos
Message 3 of 6
(8,174 Views)

Unfortunately, this seems to behave essentially identically to what I had before, at least for me.  Did you test that it would work on your machine? 

0 Kudos
Message 4 of 6
(8,151 Views)
I did test it. I only changed the TestRecvKey-2_UPDATE.vi. You should notice that the control light for the Shift and ctrl keys now stays on when the button is held down. It also tells you that you have two keys press when you look at the number of keys. To simulate the same as the keyboard you will have to keep track of the control key to know if it is press when another key is hit. To do the simulated control you will have to send two signals ctrl pressed? and key that was pressed? to receive the command you will have to do the same thing. You will have to turn on the ctrl light and give it a key code for received. This should allow you to simulate ctrl and key commands. Do you understand the concept?
Tim
GHSP
0 Kudos
Message 5 of 6
(8,145 Views)
I vaguely understand the concept, but I run my TestSendKey, and the TestRecvKey-2_UPDATE behaves just as my TestRecvKey does.  It does not get the K key press.  I suppose maybe I don't understand something.  How would you suggest to modify the TestSendKey?  I think I am sending the two key presses separately, even waiting in between the two.  I've changed the timing to no avail, even slowed everything down so much that I could use execution highlighting, and it really looks like the second key press is never really sent.  I watch Simulate Keyboard run with character "K", and TestRecv does not receive the Key Down event.  Instead, I watch the execution in TestSendKey-2... proceed to the key up, and then TestRecvKey registers the key up event, and turns off the Ctrl light.
 
Marcus
 
Updated TestSendKey (slowed down so execution highlighting works) and Simulate Keyboard 8.5 attached.  I changed the timeout in TestRecvKey-2_UPDATED to 1500 (ms).
 
Download All
0 Kudos
Message 6 of 6
(8,127 Views)