LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pause Resume mouse/keyboard macro

Solved!
Go to solution

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

0 Kudos
Message 1 of 5
(3,314 Views)
Solution
Accepted by topic author Viper

Hello Viper

You can use Input Device Control pallete from Connectivity to capture keyboard keys.

 

captureKeyboard.png

0 Kudos
Message 2 of 5
(3,307 Views)

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

0 Kudos
Message 3 of 5
(3,284 Views)

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.

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

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.

0 Kudos
Message 5 of 5
(3,257 Views)