some important knowlege about Threads in AHK - please read carefully to understand
it explains e.g why a while loop under hotkey1 is stopping (if its still running by a held down button) when activating a whileloop in hotkey2.
(same for timers)
https://www.autohotkey.com/docs/misc/Threads.htm
basically:
" If a second thread is started ā such as by pressing another hotkey while the previous is still running ā the current thread will be interrupted (temporarily halted) to allow the new thread to become current
When the current thread finishes, the one most recently interrupted will be resumed, and so on "
testscript reflected that perfectly, if a second hotkey was pressed while a former one was already kept pressing, the second hotkeys action went live and the stuff from hotkey1 got halted unless you releaseed hotkey2.
that doesnt affect the GetKeyState() ability to simultaneous ask multiple keys about their state.
So, if you have actually bound hotkeys for Lbutton and Rbutton, the recently pressed one (and its commands) getting active while the previous one gets halted. even though youre still pressing it.
If you actually want to deal with simultaneous Mousebuttons, you need to do that inside a hotkeys/thread command. aka dont have a hotkey for each of the simultaneous pressed keys, that just wont work its for held down keys.
(not to talk about gaming keyboards and n-key rollover etc)
Summary
Suspend
;#maxthreadsperhotkey 2
;#MaxHotkeysPerInterval 100
#usehook
f11::Suspend
f12::ExitApp
; ### some blatant test for while / hotkey threading / timer threading (in notepad)
; ### start notepad, start script, move cursor inside notepad, activate script by f11, press a -> 0 , keep
; ### pressed, -> 0000 , keep ressing a, now additionally press s, -> 111111, no more 0. lift s, keep pressing
; ### a - 000 again. etc
a::
SetTimer, timer1, on
return
/*
while GetKeyState("a", "P")
{
send 0
sleep 1000
}
Return
*/
s::
SetTimer, timer2, on
;SetTimer, timer4, on
return
/*
while GetKeyState("s", "P")
{
send 1
sleep 1000
}
Return
*/
d::
SetTimer, timer3, on
return
f::
while GetKeyState("f", "P")
{
send 2
sleep 1000
}
return
timer1:
while GetKeyState("a", "P")
{
send 0
sleep 1000
}
return
timer2:
while GetKeyState("s", "P")
{
send 1
sleep 1000
}
return
timer3:
while (GetKeyState("d", "P") && GetKeyState("f", "P"))
{
send 1
sleep 1000
send 0
}
return
timer4:
while GetKeyState("s", "P")
{
send -
sleep 1000
}
return
if you outcomment the whiles in timer1 and timer2, you will get the oscillating 10101010, because the timer just runs, sends the key and stops til its restarted (default period is 250). But a while loop keeps the a current timer instance running obviosuly so it gets pushed back to halt if another timer comes active.
that also means, that if you want truly independent hotkey actions, you may need to run a second AHK script instance