multiple hotkey toggles arent working simultaneously

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fqrs
Posts: 4
Joined: 06 Aug 2022, 18:57

multiple hotkey toggles arent working simultaneously

Post by fqrs » 06 Aug 2022, 19:10

im trying to get multiple toggle hotkeys
they work fine on their own but they dont work together at the same time it alternates between one working and the other when i press a hotkey

Code: Select all

RControl::
toggle2:=!toggle2
if toggle2
{
    Send {s down}
    Send {d down}
}
else
{
    Send {s up}
    Send {d up}
}

End::
toggle1:=!toggle1
if toggle1
    Send {Space down}
else
    Send {Space up}
[Mod edit: [code][/code] tags added.]

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: multiple hotkey toggles arent working simultaneously

Post by mikeyww » 06 Aug 2022, 20:06

Welcome to this AutoHotkey forum!

Multi-line hotkey routines usually end with a :arrow: Return command. Look at the documentation for some examples. Using the program

Have a look at the :arrow: KeyHistory.

If your revised script does not work:
1. Post the revised script.
2. Indicate what happens when you run it.
3. Indicate what should happen instead, step by step.

Test your script in Notepad.

Code: Select all

OnExit("done")

RCtrl::
If GetKeyState("s")
     Send {s up}{d up}
Else Send {s down}{d down}
Return

End::
If GetKeyState("Space")
     Send {Space up}
Else Send {Space down}
Return

done(exitReason, exitCode) {
 Send {s up}{d up}{Space up}
 SoundBeep, 1500
}

fqrs
Posts: 4
Joined: 06 Aug 2022, 18:57

Re: multiple hotkey toggles arent working simultaneously

Post by fqrs » 07 Aug 2022, 09:04

that worked! thanks for helping and sorry for being stupid

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: multiple hotkey toggles arent working simultaneously

Post by mikeyww » 07 Aug 2022, 09:25

No worries. One finding here is that you don't need a toggle just to send a key up or down, because you can check the key state instead. Another finding is that "resetting" the key state upon exit can be a good idea, so that keys don't stay stuck down.

Post Reply

Return to “Ask for Help (v1)”