07-25-2012 12:15 PM
Greetings,
I am writing a macro using user32.dll calls to control the mouse and keyboard. I'm using this macro to control an external application (a test client). I pull the application to the top of the windows desktop and then through a series of mouse moves, click and keystrokes control this program.
I need to pause the macro running in labview to make adjustments (see the attached example). The example uses the escape key to toggle (bound to the esc key) between the run and pause states. However this doesn't work if the labview window doesn't have the focus or the run control is hidden. I need a method to monitor the keyboard even when labview isn't on top.
Any suggestions? My default will be to use the user32.dll getKeyState in a loop but will that always guarantee to trap the key press?
Norm
Solved! Go to Solution.
07-25-2012 12:53 PM
07-26-2012 11:25 AM
Thanks PiDi. I attached my example with your improvement. Please note that if the wait timeout is to large then it won't capture the key press reliably. Couldn't find good documentation on the getKeyboadState used in the lvinput.dll. Wonder what the best time is for loop time without dropping it to zero.
Norm
07-27-2012 09:39 AM
If you want to make the wait timeout shorter without risking multiple toggles per key press, add functionality to wait until the escape key is released. See attached image for an example of this.
07-27-2012 12:04 PM
It's actually that I want to increase the wait. I typacally use 200 ms but if I do that I can miss a keystroke. There is some amout of time that the dll holds the keystroke. If you only run the vi every 200 ms you will miss many keystrokes which gives a bad user experience. So I decreased the wait to only 100ms and it seems to work OK but still not 100%. I'd rather not burn the increased cpu cycles of a shorter wait in the loop.