Posts: 102
Threads: 30
Joined: Mar 2018
I have the following for automatic mouse clicking (folder/web link) when the "hand icon" appears:
Macro
Hand
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?
Posts: 1,337
Threads: 61
Joined: Jul 2006
check out this topic
WaitForKeyOrMouse
Posts: 102
Threads: 30
Joined: Mar 2018
Awesome! Thanks, very helpful.
Posts: 102
Threads: 30
Joined: Mar 2018
12-23-2019, 01:35 AM
(This post was last modified: 12-23-2019, 02:09 PM by InterestedNewbie.)
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!
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)
Posts: 12,086
Threads: 142
Joined: Dec 2002
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.
Posts: 102
Threads: 30
Joined: Mar 2018
12-23-2019, 08:35 PM
(This post was last modified: 12-23-2019, 08:37 PM by InterestedNewbie.)
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 ?
Posts: 12,086
Threads: 142
Joined: Dec 2002
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
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
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
Posts: 102
Threads: 30
Joined: Mar 2018
Thanks again Gintaras,
That's a much cleaner way indeed.