Mouse Click Detector - Bug

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
dpsl20
Newbie
Posts: 2
Joined: Sun Jan 27, 2019 2:44 pm

Mouse Click Detector - Bug

Post by dpsl20 » Wed Aug 28, 2019 11:54 am

Hi, I'm using a script I found here on the forum to detect a user mouse click and continue the macro. It performs some mouse click and keystrokes before this script is encountered, and the first run through, it often has a false positive click detection when no click was actually performed. Even with a 1 second delay in front, I still get errors intermittently. Is there a way to reset the key state or a better script that would be more reliable?

Extra details: I'm running these executables with Autohotkey triggers. Quite strangely, I have a completely separate macro that I use frequently, and at the end of it, it presses the hotkey to trigger this macro with the bug. But when my buggy macro is triggered by that other macro, the error occurs less frequently.


Thank you.

Label>Loop
LibFunc>user32,GetAsyncKeyState,keystate,1
Wait>0.04
If>keystate<>0
Message>Great answer
Wait>0.35
PushButton>Macro Scheduler Message,&OK
Wait>.6
Goto>Postloop
endif
Goto>Loop
Label>Postloop

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Mouse Click Detector - Bug

Post by JRL » Thu Aug 29, 2019 7:06 pm

Code: Select all

OnEvent>Key_Down,VK01,0,srtClick
Let>Keystate=0

Label>Loop
Wait>0.04
If>keystate<>0
Let>Keystate=0
Message>Great answer
Wait>0.35
PushButton>Macro Scheduler Message,&OK
Wait>.6
Goto>Postloop
endif
Goto>Loop
Label>Postloop


SRT>srtClick
  Let>keystate=1
END>srtClick

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts