Use threading here. After the print command is given, just start the stream, which will simulate the keystroke required to close the window.
Here is an example of code that closes a dialog box that requires you to press enter.
Start the stream after printing starts:
'Declare a thread object to do the keyboard press events.
Dim thrd as Thread
thrd = New Thread(AddressOf ThreadTask)
thrd.IsBackground = True
thrd.Start()
, , , . escape-, .
Private Sub ThreadTask()
Thread.Sleep(100)
SendKeys.SendWait("{TAB}")
Thread.Sleep(10)
SendKeys.SendWait("{ENTER}")
End Sub