keyboard-shortcuts - 在 AutoHotkey 中检测双键按下

标签 keyboard-shortcuts keyboard-events autohotkey

当用户双击“按下”esc 键时,我想在 AutoHotkey 中触发一个事件。但是,如果不是双击(比如在一秒钟内),让转义键进入焦点应用程序。

我该怎么做呢?

到目前为止,我已经想出了这个,但我不知道如何检查第二次按下转义键:

~Esc::

    Input, TextEntry1, L1 T1
    endKey=%ErrorLevel%

    if( endKey != "Timeout" )
    {
        ; perform my double press operation
        WinMinimize, A
    }
return

最佳答案

AutoHotkey documentation 中找到了答案!

; Example #4: Detects when a key has been double-pressed (similar to double-click).
; KeyWait is used to stop the keyboard's auto-repeat feature from creating an unwanted
; double-press when you hold down the RControl key to modify another key.  It does this by
; keeping the hotkey's thread running, which blocks the auto-repeats by relying upon
; #MaxThreadsPerHotkey being at its default setting of 1.
; Note: There is a more elaborate script to distinguish between single, double, and
; triple-presses at the bottom of the SetTimer page.

~RControl::
if (A_PriorHotkey <> "~RControl" or A_TimeSincePriorHotkey > 400)
{
    ; Too much time between presses, so this isn't a double-press.
    KeyWait, RControl
    return
}
MsgBox You double-pressed the right control key.
return

所以对于我的情况:
~Esc::
if (A_PriorHotkey <> "~Esc" or A_TimeSincePriorHotkey > 400)
{
    ; Too much time between presses, so this isn't a double-press.
    KeyWait, Esc
    return
}
WinMinimize, A
return

关于keyboard-shortcuts - 在 AutoHotkey 中检测双键按下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1794258/

相关文章:

cocoa - 如何处理 Cocoa 应用程序中的 ESC 键?

visual-studio-code - 如何导航回 Visual Studio Code 中的最后一个光标位置?

objective-c - 触发事件的全局监视器后,如何在聚焦的 NSTextfield(在我的应用程序之外)上写入?

regex - 删除单行换行符,保留 "empty"行

autohotkey - 右键单击工具栏Window321 autohotkey

autohotkey - 如何绑定(bind)鼠标滚轮以用某个键向下滚动,这个键是..(AHK)

windows - 通过快捷键在 TotalCommander 中运行 Git 控制台

unix - 你知道任何针对程序员的 "best practice"或 "what works"vi 教程吗?

python - 如何拦截在 Python 程序的终端窗口中(且仅在)中按下的键?

shell - 在shell脚本中使用SCP时如何响应密码提示?