don't blink
don't blink

Reputation: 101

AHK how to stop timer immediately?

SetTimer, Test, 1000
Return

Test:
Send, a
Sleep, 3000
Send, b
Sleep, 3000
Send, c
Sleep, 3000
Return

1::
Send, x
SetTimer, Test, Off
Return

If I press "1" on 5th second, result will be: "axbc"

How to make timer stop running its content immediately, so in case above result would be "ax"?

Upvotes: 0

Views: 1046

Answers (1)

Spyre
Spyre

Reputation: 2344

One way of doing it by checking whether the hotkey has been triggered (via the state variable) after every sleep cycle

;state:=0 ;state is zero by default
SetTimer, Test, 1000
Return

Test:
Send, a
Sleep, 3000
if(state)
return
Send, b
Sleep, 3000
if(state)
return
Send, c
Sleep, 3000
Return

1::
Send, x
SetTimer, Test, Off
state := 1
Return

Upvotes: 1

Related Questions