检测在AutoHotkey中的双键按下 [英] Detect a double key press in AutoHotkey

查看:354
本文介绍了检测在AutoHotkey中的双键按下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户两次按下" esc 键时,我想在AutoHotkey中触发一个事件.但是,如果不是按两次(例如在一秒钟之内),请让逃逸按键进入焦点的应用程序.

I'd like to trigger an event in AutoHotkey when the user double "presses" the esc key. But let the escape keystroke go through to the app in focus if it's not a double press (say within the space of a second).

我将如何去做?

到目前为止,我已经提出了这个建议,但是我不知道如何检查第二次退出键的输入:

I've come up with this so far, but I can't work out how to check for the second escape key press:

~Esc::

    Input, TextEntry1, L1 T1
    endKey=%ErrorLevel%

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

推荐答案

AutoHotkey文档

; 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

这篇关于检测在AutoHotkey中的双键按下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆