2009-11-25 92 views
22

我想在用戶雙擊「按下」鍵時觸發AutoHotkey中的事件。但如果不是雙擊(比如在一秒鐘內),讓逃生按鍵進入應用程序。檢測AutoHotkey中的雙鍵按

我該如何去做這件事?

我想出這個到目前爲止,但我不知道如何來檢查第二回避按鍵:

~Esc:: 

    Input, TextEntry1, L1 T1 
    endKey=%ErrorLevel% 

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

回答

29

發現在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 
+6

的AutoHotkey有一個最好的Windows CHM幫助過的文件! – 2012-12-07 03:39:19

+1

對於那些正在尋找處理雙擊的人(就像我一樣)。這個答案同樣適用於'〜LButton'。 – 2015-06-19 08:44:35

1

有了上面的腳本,我發現我想檢測按鈕正在forwared到程序(即「〜」前綴) 。

這似乎這樣的伎倆,我(我想檢測雙「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