kjcdude Posted November 24, 2007 Share Posted November 24, 2007 I need to figure out how to wait for a window to exist. The window pops up in the background, and it can take a few seconds to popup. Right now i just have it sleep for a few seconds then force activate it, but i would feel more confident if there is a more secure version. Link to comment Share on other sites More sharing options...
Emperor Posted November 24, 2007 Share Posted November 24, 2007 Run("notepad.exe") ; ; Wait for the window to exist ; WinWait("Untitled") ; ; Wait for the window to become visible ; Do Local $Wait = WinGetState("Untitled") Sleep(10) Until BitAND($Wait, 2) ; ; Activate the window ; WinActivate("Untitled") Link to comment Share on other sites More sharing options...
Armand Posted November 24, 2007 Share Posted November 24, 2007 you can also switch the 'run' command with 'RunWait' which will have the same results [u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?! Link to comment Share on other sites More sharing options...
zfisherdrums Posted November 24, 2007 Share Posted November 24, 2007 Hello Armand, you can also switch the 'run' command with 'RunWait' which will have the same results Do you have an example of this? My understanding of RunWait is that it will pause the script until the process is closed. ;~ Runs an external program and pauses script execution until the program finishes. RunWait( "notepad.exe" ) ConsoleWrite( "Script execution will now continue..." & @CRLF) Zach... Identify .NET controls by their design time namesLazyReader© could have read all this for you. Unit Testing for AutoItFolder WatcherWord Doc ComparisonThis here blog... Link to comment Share on other sites More sharing options...
Armand Posted November 24, 2007 Share Posted November 24, 2007 (edited) and as i understand from his question he doesn't need it to continue while he is waiting PWNED! Edited November 24, 2007 by Armand [u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?! Link to comment Share on other sites More sharing options...
zfisherdrums Posted November 24, 2007 Share Posted November 24, 2007 PWNED!Indeed. My understanding is that he needs to do something with the window that belongs to the launched process. I took Emperor's working example and replaced 'Run' with 'RunWait' as you suggested. Then I ran it with debug mode turned on. Notepad appears and the debug shows that the script has paused here: Line: @error-@extended: Line syntax 0001: 0-0: #AutoIt3Wrapper_run_debug_mode = Y 0002: 0-0: RunWait("notepad.exe") It does not resume until I close that instance of Notepad. Once I do that, the script pauses on this line: 0006: 0-0: WinWait("Untitled") It does not resume until I manually open a new instance of Notepad. These behaviors do not manifest in the original example. This means one of two things: 1 ) My implementation of 'RunWait' is incorrect 2 ) RunWait will not have the same result regardless of implementation. I don't mean to beleaguer the point; I'm just interested in seeing how you were able to do it. Zach... Identify .NET controls by their design time namesLazyReader© could have read all this for you. Unit Testing for AutoItFolder WatcherWord Doc ComparisonThis here blog... Link to comment Share on other sites More sharing options...
Armand Posted November 24, 2007 Share Posted November 24, 2007 (edited) and as i understand from his question he doesn't need it to continue while he is waiting PWNED! anyhow since we're playing with it... and i am so freakin' sleepy... it's 9am here and i've been up all night with my stupid script! Opt("WinTitleMatchMode", 4) $proc = Run("Notepad.exe", "", @SW_SHOW,7) While 1 If WinWaitActive("Untitled") = 1 Then ExitLoop ;~ Sleep(1000); in case it takes that process a while to load... WEnd Send("Not PWND, was too damn tired to PWN :)",1) While WinExists($proc)=1 WEnd Exit ___________________ just in case you are realy wondering, 'runwait' runs a process and holds the script untill the child process doesn't exists anymore! Edited November 24, 2007 by Armand [u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?! Link to comment Share on other sites More sharing options...
kjcdude Posted November 24, 2007 Author Share Posted November 24, 2007 Well the program is actually launched from another program, so i have no control over how it opens. Right before it opens my script presses enter then waits 10 seconds and forces the new window to come to the front. Link to comment Share on other sites More sharing options...
zfisherdrums Posted November 24, 2007 Share Posted November 24, 2007 Hello 'kjcdude',Well the program is actually launched from another program, so i have no control over how it opens.Right before it opens my script presses enter then waits 10 seconds and forces the new window to come to the front.Emperor's suggestion should still be valid in your scenario. Simply remove 'Run( "notepad.exe" )' from the example and replace window titles as appropriate. Let us know if it works.Zach... Identify .NET controls by their design time namesLazyReader© could have read all this for you. Unit Testing for AutoItFolder WatcherWord Doc ComparisonThis here blog... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now