2009-11-25 11 views
22

Je souhaite déclencher un événement dans AutoHotkey lorsque l'utilisateur double "appuie" sur la touche esc. Mais laissez la touche d'échappement passer à l'application en cours si ce n'est pas une double pression (disons dans l'espace d'une seconde).Détection d'une double touche dans AutoHotkey

Comment ferais-je cela?

Je suis venu avec ce jusqu'à présent, mais je ne peux pas travailler comment vérifier pour la deuxième fuite sur la touche:

~Esc:: 

    Input, TextEntry1, L1 T1 
    endKey=%ErrorLevel% 

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

Répondre

29

a trouvé la réponse dans le 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 

Donc, pour mon cas:

~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 a l'un des meilleurs de Windows CHM aide les fichiers jamais! –

+1

Pour ceux qui cherchent à gérer les doubles-clics (comme je l'ai fait). Cette réponse fonctionne avec '~ LButton,' de même. –

1

Avec le script ci-dessus, je trouve que le bouton que je voulais détecter était forwared au programme (le préfixe « ~ ») .

Cela semble faire l'affaire pour moi (je voulais détecter un double "d" presse)

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