Autohotkey多个映射到相同功能的热键 [英] Autohotkey multiple hotkeys mapping to the same function

查看:348
本文介绍了Autohotkey多个映射到相同功能的热键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个热键,它们的功能相同,我有多个,因此我可以在当时碰到的任何地方调用它们,并可以在多个键盘上使用,例如:

I have several hotkeys that all do the same things, I have multiples so I can call them wherever my hands happen to be at the time and can be used on multiple keyboards eg:

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

有什么方法可以将这些东西组合成一行,而不必到处重复呢?

Is there any way to combine these things onto one line without having to repeat myself all over the place?

推荐答案

一行中无法完成多个热键定义,至少没有真正的技巧.
尽管如此,仍有一些方法可以简化脚本:

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:

这是为多个热键分配相同功能的最简单,最直接的方法.通过简单地将热键一个写在另一个热键下,仅向最后一个热键分配一个或几个命令,即可工作:

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}

方法2:动态热键创建

使用Hotkey命令,可以在运行时将标签分配给热键.这意味着它们可以循环使用:

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

在运行时创建的热键的性能不如硬编码的热键,但是在大多数情况下,您不会注意到它们之间的差异.我仍然会使用方法1,因为它更具可读性.

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.

这篇关于Autohotkey多个映射到相同功能的热键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆