HowDoIShotWeb Posted May 6, 2012 Share Posted May 6, 2012 Hi, thanks for the previous help. I am currently trying to make it so the script will not run if a certain window is not open (it will wait for 5 seconds before timing out), but will run if the window is open but may not be active (it will switch to the active window in this case and run the script). What I have so far was auto generated from the Au3Recorder and I read I should put a number in the timeout parameter so it will wait for X# of seconds then timeout (exit script): Func _WinWaitActivate($title,$text,$timeout=5) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,5) EndFunc ;later on as I recall the func: _WinWaitActivate("Untitled - Notepad","") MouseClick("left",74,681,1) Send("Hello world") But right now when I run the script, even if the "Untitled - Notepad" window is not open, the script will still run, and perform the actions without the window open. How should I fix this? Thanks in advance Link to comment Share on other sites More sharing options...
JohnOne Posted May 6, 2012 Share Posted May 6, 2012 (edited) Func _WinWaitActivate($title, $text, $timeout = 5) WinWait($title, $text, $timeout) If Not WinActive($title, $text) Then WinActivate($title, $text) If Not WinWaitActive($title, $text, 5) Then Return 0 Else Return 1 EndIf EndFunc ;==>_WinWaitActivate ;later on as I recall the func: If _WinWaitActivate("Untitled - Notepad", "") Then MouseClick("left", 74, 681, 1) Send("Hello world") Else Exit EndIf EDIT: By the way, it is customary here if you are going to thank someone, to do it in the thread you got the help not some random future thread. Alternatively you can use the like button as a thanks. Good luck with your future coding. Edited May 6, 2012 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
HowDoIShotWeb Posted May 6, 2012 Author Share Posted May 6, 2012 Ahh ok, thank you. Link to comment Share on other sites More sharing options...
mrmacro Posted August 31, 2017 Share Posted August 31, 2017 I know this is an old post but i am trying to get my head around which to use and exactly how WinWaitActive works. I read the manual but sill a little confused I just need someone to help me understand and help explain to me i have a full script that works but only need clarification on the below part of the code this basically checks if myprogram.exe is open if it is then it closes it and reopens but i want the program when reopened to then have the focus and if i use WinWaitActive("My Program window name") then click the window myself this works fine but i want it to automatically select the window but if its not there to wait until it is ,so hence why i believe WinWaitActive("My Program window name") would be better as its waiting but if i dont click the window then it waits for ever , which i believe is what is supposed to be happening if i use the code below then i believe that once the script has processed WinActivate("My Program window name") it will move on, but sometimes the window may not be open so will cause errors but using below code WinActivate("My Program window name") WinWaitActive("My Program window name") WinActivate("My Program window name") this works too without me selecting it with the mouse but i dont see why i need to activate it twice full code sampe of what i need help with below #Region myProgramCheck --- Func myProgramCheck() Sleep(2000) While 1 ; Opens up a WHILE loop, with 1 as a constant, so it is infinite If ProcessExists("myProgram.exe") Then ProcessClose("myProgram.exe") ;Run("C:\Pro;gram Files (x86)\myProgram.exe") ; if the process of myProgram.exe doesn't exist, it starts it Sleep(1000) ; Puts the script to sleep for 1 seconds so it doesn't chew CPU power ElseIf Not ProcessExists("myProgram.exe") Then Run("C:\Program Files (x86)\myProgram.exe") ; if the process of myProgram.exe doesn't exist, it starts it Sleep(1000) ; Puts the script to sleep for 1 seconds so it doesn't chew CPU power WinActivate("My Program window name") ExitLoop EndIf WEnd ; Closes the loop, tells it to go back to the beginning EndFunc ;==>myProgramCheck #EndRegion myProgramCheck --- ;which do i use?? WinWait("My Program window name") WinWaitActive("My Program window name") WinActivate("My Program window name") hope you can help clarify which to use Many thanks Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 31, 2017 Moderators Share Posted August 31, 2017 I guess I am a bit confused. Are you saying, once the window appears, sometimes it is active and sometimes it is not? Personally, I would just do it like this: WinWait("My Program Window", 60) ;Wait for 60 seconds for the window to appear WinActivate("My Program Window", "") ;Bring the window into focus once it exists You could even put in an If statement after the WinWait, to handle the exception of the window not existing (look at WinExist) after the 60 seconds, or whatever timeout you choose). mrmacro 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
mrmacro Posted August 31, 2017 Share Posted August 31, 2017 it seems to activate but I wanted to be 100% sure that it does and that it can't continue without it actually having the window to activate and then continuing I just wanted really to fully understand how autoit processes the requests I understand that if I use WinWaitActive("My Program window name") that it waits until that window is clicked and then becomes active, this I tested so I get this but its fully knowing when to use each other command and that if one of the others is better to use to get what I want but will see how I get on with an if statement Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 31, 2017 Moderators Share Posted August 31, 2017 If you are clicking on the window (buttons, entering info, etc.), have you looked at the Control* commands in the help file? Then it doesn't matter if the window is active or not, as long as it exists. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
mrmacro Posted August 31, 2017 Share Posted August 31, 2017 I am later in the code using the control commands it was just which was better to use in the opinion of people that have been using autoit for a long while either winwait() winactivate() winwaitactive() what I found works is below but most of what I done it 100% trial and error not really a full understanding even though I read the manual, sometimes other peoples input helps explain things better, then the manual makes sense WinActivate("My Program window name") WinWaitActive("My Program window name") WinActivate("My Program window name") WinActivate("My Program") Sleep(3000) ControlSend("My Program", "", "[CLASS:WindowsForms10.Window.8.app.0.141b42a_r12_ad1; INSTANCE:3]", $pinDigit1) 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