Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wait for mouse movement - any
#1
I have the following for automatic mouse clicking (folder/web link) when the "hand icon" appears:

Macro Hand
Code:
Copy      Help
rep 100
,wait 0 CU IDC_HAND
,2
,lef

The problem is that I then need it to stop auto clicking until the mouse cursor is moved again. "Wait for mouse movement" so to speak. 
(not to a specific coordinate, but it should detect any mouse movement, in any direction or any amount of pixels).

Is this possible with QM?
#2
check out this topic

WaitForKeyOrMouse
#3
Awesome! Thanks, very helpful.
#4
Following the above suggestion I trimmed down the script as I only need mouse move and I commented out the "out" section. I added two seconds Wait and single Left Click instead as I want the script to automatically left click two seconds after moving the mouse. However, the code below doesn't work and crashes both QM as well as some other programs (Warning: thread of <open ":2841:">Test has been terminated. It was hung and could not be ended correctly. It is recommended to restart QM).

The problem is probably in either int k=wParam
 or str what action ?

Any suggestions would be welcome!
 
Code:
Copy      Help
int hmouse=SetWindowsHookEx(WH_MOUSE_LL &sub.MouseProc _hinst 0)
opt waitmsg 1
wait -1
UnhookWindowsHookEx hmouse

#sub MouseProc
function nCode wParam MSLLHOOKSTRUCT*x

if(nCode!=HC_ACTION) goto gr

int k=wParam
str what action

sel k
,case WM_MOUSEMOVE what="move"

sel k
,case [WM_LBUTTONDOWN,WM_RBUTTONDOWN,WM_MBUTTONDOWN,WM_XBUTTONDOWN] action="pressed"
,case [WM_LBUTTONUP,WM_RBUTTONUP,WM_MBUTTONUP,WM_XBUTTONUP] action="released"

/out "mouse %s %s at %i %i" what action x.pt.x x.pt.y
2
lef

;gr
ret CallNextHookEx(0 nCode wParam x)
#5
Hook functions must be as fast as possible and cannot wait. If need to wait, do it in other thread. For example use mac or tim.
#6
Thanks Gintaras,

mac seems to work where the macro (needs to be a function) is:

2
lef

But it will repeat itself causing a gazillion threads :-(.
How can I limit it to just one ?
#7
Maybe the lef clicks the Run button.
But why to add 2 lef or mac in WaitForKeyOrMouse? If want to modify it, clone it and modify, then call from your macro.
Macro Macro333
Code:
Copy      Help
rep 100
,wait 0 CU IDC_HAND
,2
,lef
,WaitForKeyOrMouseClone
or if don't want to use WaitForKeyOrMouse, can create your wait function:
Macro Macro333
Code:
Copy      Help
rep 100
,wait 0 CU IDC_HAND
,2
,lef
,sub.WaitForMouseMove


#sub WaitForMouseMove
POINT p1 p2; xm p1
rep
,0.05
,xm p2
,if(p2.x!=p1.x or p2.y!=p1.y) break
#8
Thanks again Gintaras,

That's a much cleaner way indeed.


Forum Jump:


Users browsing this thread: 1 Guest(s)