I've replaced sleeps with timers.
Because of this, the Q-key loop and the Space-key loop can run simultaneously when both keys are pressed:
Code: Select all
q:: ;Q-Loop breaks if Q is up
SoundBeep, 4000, 20
Goto("1|q", 500)
1|q:
SoundBeep, 2000, 20
Goto("2|q", 500)
2|q:
SoundBeep, 1000, 20
Goto("q", 500)
Space:: ;Space-Loop breaks if Space is up
SoundBeep, 3000, 20
Goto("1|Space", 500)
1|Space:
SoundBeep, 3400, 20
Goto("2|Space", 500)
2|Space:
SoundBeep, 3800, 20
Goto("Space", 500)
Goto(Label, Time)
{ ;Goto Label (= [Integer|]Key ) after Time when Key is down
IF Down:=GetKeyState(Key:=SubStr(A_ThisLabel
,InStr(A_ThisLabel,"|")+1),"P")
SetTimer,% Label,% -Abs(Time)
Hotkey,% Key,% Down?"GotoExit":Key
GotoExit:
Exit
}