04-10-2009 05:12 PM
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.
04-12-2009 08:37 AM
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.
04-13-2009 07:32 AM
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.
04-13-2009 11:29 AM
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?
04-13-2009 11:53 AM
04-13-2009 01:27 PM