It is the sleep commands that are making it not able to properly run asynch
AHK is NOT a multi-threaded language, it fakes it.
Code: Select all
SetTimer, gun1, 1200
sleep 600
SetTimer, gun2, 1200
so @ 1200, it fires Gun1
Code: Select all
sendinput {1 down}
sleep 1000
sendinput {1 up}
Gun1 presses 1, then sleeps for 600ms.
Gun2 should run 600ms after Gun1, but it does not, because the
Sleep 600 command in Gun1 is BLOCKING.
A much much better way to handle this:
Code: Select all
#SingleInstance force
input_state := 0
return
Numpad0::
if (input_state)
return ; input button already held. Ignore the key repeat
input_state := 1
gosub, B1Press
SetTimer, B2Press, -600
return
Numpad0 up::
input_state := 0
; Stop all timers
SetTimer, B1Press, Off
SetTimer, B2Press, Off
SetTimer, B1Release, Off
SetTimer, B2Release, Off
; Release any held keys
Send {1 up}{2 up}
return
B1Press:
SetTimer, B1Release, -600
Send {1 Down}
return
B2Press:
SetTimer, B2Release, -600
Send {2 Down}
return
B1Release:
SetTimer, B1Press, -600
Send {1 up}
return
B2Release:
SetTimer, B2Press, -600
Send {2 up}
return
FYI a negative value for SetTimer means "Run only once". ie it does not repeat.
What I am doing here is that when the button is pressed, I start a timer to send release.
When it releases, I start a timer to press