How to toggle a set of keybinds on and off?

大兔子大兔子 提交于 2020-01-05 02:03:26

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/16315817/how-to-toggle-a-set-of-keybinds-on-and-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!