AutoHotkey:测试键序列?

AutoHotkey: Test for key sequence?

我的意思是,如果我按下 A 键,它会在第二次按下时测试 B 键,如果是,它会测试 C 键。如果有任何不是它正在等待的密钥,它会返回到 A 密钥。

这可以通过将键 A 分配为 Hotkey and then having a Input command evaluate the next key press. Evaulate the key pressed using If 命令来实现,如果为真,则让另一个输入命令评估下一个按键等...

在文档的输入页面上似乎有此方法的示例代码。

; This is a working hotkey example.  Since the hotkey has the tilde (~)
; prefix, its own keystroke will pass through to the active window.
; Thus, if you type [btw (or one of the other match
; phrases) in any editor, the script will automatically perform an
; action of your choice (such as replacing the typed text):

~[::
Input, UserInput, V T5 L4 C, {enter}.{esc}{tab}, btw,otoh,fl,ahk,ca
if (ErrorLevel = "Max")
{
    MsgBox, You entered "%UserInput%", which is the maximum length of text.
    return
}
if (ErrorLevel = "Timeout")
{
    MsgBox, You entered "%UserInput%" at which time the input timed out.
    return
}
if (ErrorLevel = "NewInput")
    return
If InStr(ErrorLevel, "EndKey:")
{
    MsgBox, You entered "%UserInput%" and terminated the input with %ErrorLevel%.
    return
}
; Otherwise, a match was found.
if (UserInput = "btw")
    Send, {backspace 4}by the way
else if (UserInput = "otoh")
    Send, {backspace 5}on the other hand
else if (UserInput = "fl")
    Send, {backspace 3}Florida
else if (UserInput = "ca")
    Send, {backspace 3}California
else if (UserInput = "ahk")
    Run, http://ahkscript.org
return

要将输入修改为仅接受 1 次击键,您只需将输入命令上的选项从 L4 更改为 L1,然后将您想要的任何键作为匹配列表放入引号中。

示例未测试但应该接近您想要的:

~A::
Input, UserInput, V T5 L1, , "B"

If (UserInput = "B")
     Input, UserInput, V T5 L1, , "C"
         If (UserInput = "C")
            .... Some more code here...