Autohotkey multiple hotkeys mapping to the same function

亡梦爱人 提交于 2019-12-06 03:39:04

Multiple hotkey definitions in one line can't be done, at least not without a genuine hack.
Still, there are ways to simplify your script:

Method 1: "Trickling hotkeys"

This is the simplest and most straight-forward way to assign multiple hotkeys the same functionality. It works by simply writing the hotkeys one below the other, only assigning the last hotkey one or several commands:

#]::
XButton2 & RButton::
SC15D & ]::Send {Media_Next}

Method 2: Dynamic hotkey creation

Using the Hotkey command, you can assign labels to hotkeys at runtime. This means, they can be used in a loop:

for i, keyName in ["#]", "XButton2 & RButton", "SC15D & ]"]
    Hotkey, % keyName, SendMediaNext

Exit

SendMediaNext: 
    Send {Media_Next}
return

Hotkeys created at runtime aren't as performant as hard-coded hotkeys, but in most cases, you won't notice a difference. I would still go with Method 1, since it's more readable.

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