Ending the output of a macro on any input Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
The Spirit
Posts: 16
Joined: 06 Mar 2022, 10:01

Ending the output of a macro on any input

Post by The Spirit » 04 Dec 2022, 08:41

How can I stop the output of a lengthy macro on any input whatsoever?
Let's assume I have the following simplified example:

Code: Select all

a::
MouseMove, 100, 200
Sleep, 50
Send, g
Sleep 100
MouseMove, 300, 400
Sleep 50
Send, k
Sleep 100
Send, i
return
Can I tell it to stop on the spot when I press another button? If I were to press another macro for example after 150 ms then they would overlap, potentially ruining both of them.
Thank you :)

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Ending the output of a macro on any input  Topic is solved

Post by mikeyww » 04 Dec 2022, 08:53

You can reload the script, or set a "stop variable" and then check that variable in your hotkey subroutine.

The Spirit
Posts: 16
Joined: 06 Mar 2022, 10:01

Re: Ending the output of a macro on any input

Post by The Spirit » 07 Dec 2022, 17:10

How would I go about it in an efficient way? The only way I can think of is having a variable, let's call it b, whose value is then switched at the start of every macro while the command that I want to be interruptable uses exactly that variable in a While equals something condition. That means I have to put b everywhere, and that still wont work on some input like left click, which I do not use a macro for.
Is there a command I could use which I only need to mention once? Something like

Code: Select all

a::
b:=GO
while (b = GO)
{
MouseMove, 100, 200
Sleep, 50
Send, g
Sleep 100
MouseMove, 300, 400
Sleep 50
Send, k
Sleep 100
Send, i
Sleep 50
b:=STOP
}
return

ON ANYTHING::
b:=STOP
return

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Ending the output of a macro on any input

Post by mikeyww » 07 Dec 2022, 19:04

Code: Select all

#InstallMouseHook
a Up::
While (A_PriorKey = "a") {
 MouseMove, 300, 700
 Sleep, 50 * (A_PriorKey = "a")
 If (A_PriorKey = "a")
  Send g
 Sleep, 100 * (A_PriorKey = "a")
}
Return

Post Reply

Return to “Ask for Help (v1)”