4

Standard system Print dialog or Save dialog is swallowing keys sent immediately after opening. Is there a way how to send keys successfully as soon as possible?

Details:

Let's have some simple use case of Print dialog, i.e. if you press Ctrl+P in Internet Explorer. Once it opens, I just want to send Alt+p to press the Print button as soon as possible. But the following script does not work:

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

It starts working when I insert Sleep 500 before Send !p. But perhaps 500 ms won't be enough in some cases. Is there some ellegant way how to insert keystrokes ASAP?

miroxlav
  • 13,008
  • 6
  • 65
  • 103

1 Answers1

2
#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

or

; 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, ...
...
user3419297
  • 3,370
  • 2
  • 11
  • 11
  • Great, works! Maybe specifying `ahk_class #32770` is little bit redundant – isn't it? – miroxlav Sep 18 '15 at 11:18
  • I see the trick was is activation. Window is immediately presented as focused (active), but it seems that it actually isn't active yet. Activation solves the problem – miroxlav Sep 18 '15 at 11:22