2

I am trying to set up a group of keybinds that I can toggle on and off with a single button press but haven't been able to find any examples anywhere.

I want ^NumpadSub to toggle these different keybinds to turn them on and off when I press ^NumpadSub.

q::w
z::s
w::up
s::down

Can anyone help on how I would set up the code to do so?

Ooker
  • 1,969
  • 4
  • 28
  • 58

1 Answers1

4

When these are the ONLY ones, you could add one more hotkey:

^NumpadSub::Suspend

This will suspend ALL hotkeys (except the one that is used for toggling suspend on/off)

Otherwise you would have to use the actual hotkey function (http://www.autohotkey.com/docs/commands/Hotkey.htm) which allows you to turn hotkeys on/off, but the hotkey function refers to labels: (go to addresses).

If you want to ONLY have these keys act a certain way when you use ONE particular application (Game), you can use the #IfWinActive command.

e.g.

SetTitleMatchMode, 2
#IfWinActive, Notepad ; Start of Notepad specific keys.
a::Send, Haha
b::SoundBeep, 500, 500
#IfWinActive ; End of Notepad specific keys.

In that situation, Check out if this works for you! I added $ signs in front of w and s because hitting q and z would trigger the execution of w and s

Hotkey, q , MyQ, On
Hotkey, z , MyZ, On
Hotkey, $w , MyW, On
Hotkey, $s , MyS, On
Return

^NumpadSub::
KeyToggle:=!KeyToggle
Hotkey, q , % (KeyToggle ? "Off": "On")
Hotkey, z , % (KeyToggle ? "Off": "On")
Hotkey, $w , % (KeyToggle ? "Off": "On")
Hotkey, $s , % (KeyToggle ? "Off": "On")
Return

MyQ:
SendInput, w
Return

MyZ:
SendInput, s
Return

MyW:
SendInput, {Up}
Return

MyS:
SendInput, {Down}
Return
Robert Ilbrink
  • 7,738
  • 2
  • 22
  • 32
  • I already have a lot of hotkeys set up and also already have a #IfWinActive set up for the game I am making these for. What I need is one key to toggle those 4 changes I had, and then toggle them back to normal when I hit that one key again. Is there any way you could lay that out for me? I tried from the link you sent but couldn't figure it out. – Garrett Muehlhauser May 01 '13 at 10:17
  • Hmmm, when I push ^NumpadSub it pops up with Error: Nonexistant Hotkey, specifically: q, and pointing to the line: Hotkey, q , % (KeyToggle ? "Off": "On") I deleted that line and it does the same for z and I assume the rest. Do you know why? Thank you so much for your time helping by the way! – Garrett Muehlhauser May 01 '13 at 19:28
  • Garrett, No idea, as I tested this before publishing and it works smoothly on my system (Windows 7, AutoHotKey_L v1.1.09.04). Have you tried this in a standalone script first, just to see? Oh b.t.w. without pressing ^NumpadSub, does the q produce a w? Alternatively if you use AHK_L, you could also use #IF (Toggle), which might be easier. – Robert Ilbrink May 02 '13 at 05:32
  • No you are right it works, must be something in my other lines of code, thanks for all the help! I will do some trial and error to see whats causing the problem. – Garrett Muehlhauser May 02 '13 at 06:47