Again, #If directives are only for determining whether a hotkey is active. It would go before a hotkey to make it conditional whether the hotkey routine is run at all. It does not make code conditional, so you wouldn't put it before a block of code as you did like a regular
If statement.
Regarding your new request, this seems like what you want it to do:
#MaxThreadsPerHotkey 2
Code: Select all
!w::
apple := !apple
while apple
{
Send {w Down}
sleep 10000
Send {w Up}
sleep, 1000
}
return
Pressing
Alt+
W a second time would stop the looping, but the thread will still need to complete its 10 seconds before releasing the W key. If you want it to immediately release the W key upon toggling it off, this should do it:
Code: Select all
!w::
apple := !apple
Send, {w Up}
while apple
{
Send {w Down}
sleep 10000
Send {w Up}
sleep, 1000
}
return
...but the thread will still be running for the rest of its time in that loop (the remaining time of the 10 seconds plus the extra second at the end. That would probably prevent it from being available to toggle back on until it completes that loop. If that's not acceptable, then you probably need to make use of
Reload in some manner.