在AutoHotkey中检测双键按下

时间:2009-11-25 02:17:27

标签: 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

2 个答案:

答案 0 :(得分:32)

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

答案 1 :(得分:2)

使用上面的脚本,我发现我想要检测的按钮正在被提供给程序(即“〜”前缀)。

这似乎对我有用(我想检测双“d”按)

d::
keywait,d
keywait,d,d t0.5 ; Increase the "t" value for a longer timeout.
if errorlevel
{
    ; pretend that nothing happened and forward the single "d"
    Send d
    return
}
; A double "d" has been detected, act accordingly.
Send {Del}
return

Source