Your attempt using a toggle variable (as per the code from your comment) is the right approach, but there are few things missing:
- Always initialize a toggle variable. Otherwise, how can you be sure what
Toggle := !Toggle
does with an unitializedToggle
? It could betrue
orfalse
; most compilers wouldn't even allow it. - I always recommend using timers when possible, especially for recurring tasks, that potentially get repeated very often.
- It is rarely neccessary to fire key sequences in maximum speed. The speed admittedly is effectively regulated by
SetBatchLines
andSetKeyDelay
. But at the latest when those delays are reduced, the send speed could not only be overkill, but also affect the target application or even your system performance. That's whySleep
orSetTimer
with an adequate delay should be used.
Here's an untested suggestion:
toggle := false
$F8::
if(toggle) {
toggle := false
SetTimer, SendSomething, Off
} else {
toggle := true
; Choose a delay here!
SetTimer, SendSomething, 100
}
return
SendSomething:
Click right
Click
Send {Numpad7}
return