2009-11-25 22 views
22

Me gustaría activar un evento en AutoHotkey cuando el usuario presiona doblemente la tecla esc. Pero deje que la tecla de escape se dirija a la aplicación enfocada si no es una pulsación doble (por ejemplo, en el espacio de un segundo).Detectar una pulsación de tecla doble en AutoHotkey

¿Cómo voy a hacer esto?

Yo he llegado con esto hasta ahora, pero no puedo encontrar la manera de comprobar si la tecla presionada segunda fuga:

~Esc:: 

    Input, TextEntry1, L1 T1 
    endKey=%ErrorLevel% 

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

Respuesta

29

encontrado la respuesta en el 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 

Así que para mi caso:

~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 tiene uno de los mejores de Windows CHM ayuda archivos nunca! –

+1

Para aquellos que buscan manejar clics dobles (como yo hice). Esta respuesta también funciona con '~ LButton,'. –

1

Con el guión anterior, descubrí que el botón i quería detectar estaba siendo forwared al programa (es decir, el prefijo "~") .

Esto parece hacer el truco para mí (yo quería para detectar una doble "D" de prensa)

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

Cuestiones relacionadas