我可以列出几个键来执行相同的操作吗? [AHK]

Can I list several keys to perform the same action? [AHK]

AHK 允许绑定键,即我们 a::z 每当按下 'a' 时触发 'z'。 如果我想在按下 'a'、'b' 或 'c' 时触发 'z' 怎么办?

我显然可以重复我的代码:

  a::z
  b::z
  c::z 

我大概可以用Gosub之类的

a::Gosub, abc
b::Gosub, abc
c::Gosub, abc

abc:
send z
return

有没有更好的说法 "if a,b, or c are pressed - fire z"?

您可以直接使用

a::
b::
c::z

我不确定确切的语法是什么,但这行得通。

我们在 codegolf.stackexchange.com,对吧?

JFF,此处使用 Hotkey 命令将 A​​-Y 分配给仅 61 个字符的 Z:

loop,25
    hotkey,% chr(a_index+64),z
return
z(){ 
    send z
}

另一种解决方案使用Hotkey动态定义热键,parse以便用户可以直接指定键列表:

; Thanks engunneer: autohotkey.com/board/topic/45636-script-to-prevent-double-typing/?p=284048
; Thanks throwaway_ye: https://www.reddit.com/r/AutoHotkey/comments/54g40q/how_can_i_bind_several_keys_to_the_same_command/d81j0we

; The following part must be located in the auto-execute section, 
; i.e. the top part of the AHK script.

keylist = 1234567890qwertzuiopasdfghjklyxcvbnm

Loop, parse, keylist
{
  Hotkey, $%A_LoopField%, SendGivenKey
}    
Return


; This can be located anywhere in the AHK file
SendGivenKey:
StringReplace, key, A_ThisHotkey, $, , All
send %key%
Return