2009-11-25 33 views
22

Tôi muốn kích hoạt sự kiện trong Tự động phát khi người dùng nhấn đúp "nhấn" phím esc. Nhưng hãy để tổ hợp phím tắt đi qua các ứng dụng tập trung nếu nó không phải là một báo chí kép (nói trong không gian của một giây).Phát hiện một phím bấm kép trong AutoHotkey

Tôi làm cách nào để thực hiện việc này?

tôi đã đi lên với điều này cho đến nay, nhưng tôi không thể làm việc ra làm thế nào để kiểm tra thứ hai thoát nhấn phím:

~Esc:: 

    Input, TextEntry1, L1 T1 
    endKey=%ErrorLevel% 

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

Trả lời

29

Tìm thấy câu trả lời trong 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 

Vì vậy, đối với trường hợp của tôi:

~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 là một trong những sản phẩm tốt nhất của Windows CHM giúp file bao giờ hết! –

+1

Đối với những người đang tìm kiếm xử lý nhấp đúp (như tôi đã làm). Câu trả lời này làm việc với '~ LButton,' tương tự như vậy. –

1

Với kịch bản trên, tôi phát hiện ra rằng vào nút i muốn phát hiện đang bị forwared cho chương trình (tức là "~" tiền tố) .

Điều này dường như làm các trick cho tôi (tôi muốn phát hiện một đôi "d" báo chí)

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

Các vấn đề liên quan