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

查看:43
本文介绍了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?

推荐答案

不能在一行中定义多个热键,至少在没有真正的 hack 的情况下不能.
不过,仍有一些方法可以简化您的脚本:

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}

方法二:动态创建热键

使用 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天全站免登陆