AutoHotKey – 等待系統對話方塊能夠接受擊鍵的優雅方式?

AutoHotKey – 等待系統對話方塊能夠接受擊鍵的優雅方式?

標準體系列印對話框或者儲存對話框正在吞嚥發送的鑰匙打開後立即。有沒有辦法盡快成功發送金鑰?

細節:

讓我們來看看一些列印對話方塊的簡單用例,即如果您在 Internet Explorer 中按Ctrl+ 。P打開後,我只想發送Alt+p來按列印盡快按鈕。但以下腳本不起作用:

#IfWinActive, ahk_class IEFrame
F2::
    Send ^p
    WinWait, Print,, 2
    Send !p   ; this has no effect if sent immediately
Return
#IfWinActive

Sleep 500當我插入before時它開始工作Send !p。但在某些情況下 500 毫秒可能還不夠。有沒有一些優雅的方法如何盡快插入擊鍵?

答案1

#IfWinActive, ahk_class IEFrame

F2:: 
    Send ^p
    WinWait, Print ahk_class #32770     ; Waits until the specified window exists
    IfWinNotActive, Print ahk_class #32770, ,WinActivate, Print ahk_class #32770
    WinWaitActive, Print ahk_class #32770   ; Waits until the specified window is active 
    Send !p
Return

#IfWinActive

或者

; WinWait, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText

WinWait, Print ahk_class #32770, WinText  ; Use Window Spy to find out a single text element of the target window 
IfWinNotActive, ...
...

相關內容