RandomClown Posted October 28, 2008 Share Posted October 28, 2008 Hello, I have been over the internet for a while now, & I didnt see how to focus on a window.Is there no way to do it? Or are my eyes bad from hours of reading? Since I didnt see it, I might have to do this instead; I wanted to write a little script that will:* Perform a "IF WinActive()" check 10 times, once per second.- If the window was active during the check, do a Goto to get out of the messy script & goto the main script.- If the window did not focus during the check, do that code then goto the script:MouseMove(@DesktopWidth/2, @DesktopHeight/2-30, 0)MouseClick("primary")ima go to sleep now.ive been reading & typing all day..thanks for reading. Link to comment Share on other sites More sharing options...
radix Posted October 28, 2008 Share Posted October 28, 2008 (edited) I didnt see how to focus on a window.If I understand right, you need to use WinActivate function. Edited October 28, 2008 by radix Link to comment Share on other sites More sharing options...
RandomClown Posted October 28, 2008 Author Share Posted October 28, 2008 (edited) oooohhh that could stand alone?I thought it was a checking thingy for If() funcs.AutoIT is more powerful then I thought.Thanks a lot!EDIT [not to double post]How would I set 2 conditions in a While statement?- There is the i++ thing [something like that] I saw in the very useful help file- Where is the &&?I want to set a While() with these conditions:- Run at most 10 times- Check if "Some Window" is up...hmm I just saw this right now: "ExitLoop".I could do an If("Some Window" is up){ExitLoop} [of course in AutoIT language], but I want to cut off 3 lines from the tiny check script if possible. Edited October 28, 2008 by RandomClown Link to comment Share on other sites More sharing options...
Nick_White Posted October 30, 2008 Share Posted October 30, 2008 $i=1While ($i<=10) If (WinActive("Window title")) Then ExitLoop EndIf $i = $i + 1 Sleep(1000)WEnd Link to comment Share on other sites More sharing options...
MHz Posted October 30, 2008 Share Posted October 30, 2008 Welcome to the forum RandomClown, How would I set 2 conditions in a While statement?- There is the i++ thing something like that I saw in the very useful help file- Where is the &&?AutoIt supports only the operators under "Language Reference" catagory in the help file supplied within the installation of AutoIt3.I want to set a While() with these conditions:- Run at most 10 times- Check if "Some Window" is upYou may use as Nick White displays or you could use a For...Next loop that is suitable for limited looping by using a counter variable. Using AdlibEnable() function may also be suitable for detection in your script. The choice is for you to make. I made example code below.; title of test window$title = 'Target Window'; create a window to test withGUICreate($title)GUISetState(); run the _Adlib() function every 2 seconds to check for the test windowAdlibEnable('_Adlib', 2000)Sleep(2000); activate the test window if neededIf Not WinActive($title) Then WinActivate($title)EndIf; loop 10 timesFor $i = 1 To 10 ; check if test window is active If WinActive($title) Then ; disable the _Adlib() function check AdlibDisable() ; show the result SplashTextOn('For...Next Loop', 'Window is active', 200, 50) Sleep(2000) SplashOff() ; enable the _Adlib() function check AdlibEnable('_Adlib', 2000) ; exit the For...Next Loop ExitLoop EndIf Sleep(500)NextSleep(5000)ExitFunc _Adlib() ; Adlib function to show result while the main code is executing SplashTextOn('_Adlib() function', 'Window is active', 200, 50) Sleep(1000) SplashOff() Sleep(250)EndFunc...hmm I just saw this right now: "ExitLoop".I could do an If("Some Window" is up){ExitLoop} [of course in AutoIT language], but I want to cut off 3 lines from the tiny check script if possible.Single line If...Then... are allowed though your mention of removing 3 lines is beyond my understanding to answer with the information supplied. Link to comment Share on other sites More sharing options...
RandomClown Posted October 31, 2008 Author Share Posted October 31, 2008 (edited) Thanks for the welcome!Hey thanks for the info guys, I just learned a few things from your responses.MHz:Single line If...Then... are allowed though your mention of removing 3 lines is beyond my understanding to answer with the information supplied.Oops! Did I write 3? I meant a lot.This is what I wrote before revisiting this thread:$i = 0While $i <= 60$i = $i + 1Sleep(1000) If WinActive("setup") ThenExitLoopEndIf WinActivate("setup")WEndWinWaitActive("setup")ControlClick("setup", "", "[CLASS:Button; INSTANCE:##]")WinWaitClose("setup")ExitThis is way more than 3 lines..I meant a lotThe code you wrote is beyond my understanding. I made the code on 1 line before & I got error messages.Is there a way to make it all on 1 line?For now, I will replace my script with Do Untils Edited November 1, 2008 by RandomClown Link to comment Share on other sites More sharing options...
MHz Posted November 1, 2008 Share Posted November 1, 2008 I made the code on 1 line before & I got error messages.Is there a way to make it all on 1 line?Controlclick() normally works with an inactive window so this may do the task as being 1 line.If WinWait("setup") And ControlClick("setup", "", "[CLASS:Button; INSTANCE:##]") Then WinWaitClose("setup") Link to comment Share on other sites More sharing options...
RandomClown Posted November 3, 2008 Author Share Posted November 3, 2008 (edited) thanksI am also trying this for buttons disabled while installing:Do Sleep(200)Until ControlCommand($title, , 'Button2', 'IsEnabled', '')ControlClick($title, "", "[CLASS:Button; INSTANCE:2]")It keeps crashing at the until.I want to make it wait until it is enabled.Did I use the wrong code?- The window is called setup; I used $title you guys showed me.- The button is named Button2, Edited November 3, 2008 by RandomClown Link to comment Share on other sites More sharing options...
MHz Posted November 3, 2008 Share Posted November 3, 2008 Do Sleep(200)Until ControlCommand($title, , 'Button2', 'IsEnabled', '')ControlClick($title, "", "[CLASS:Button; INSTANCE:2]")Put the Do keyword on a line of it's own to avoid the error condition.Do Sleep(200)Until ControlCommand($title, , 'Button2', 'IsEnabled', '')ControlClick($title, "", "[CLASS:Button; INSTANCE:2]")You can use [ CODE ] ... [/ CODE ] tags (without spaces in the tags) to post code segments in this forum. Link to comment Share on other sites More sharing options...
RandomClown Posted November 6, 2008 Author Share Posted November 6, 2008 (edited) thanks for the reminder. I forgot I was on a coding forum.hmm.Still not working.I am getting a Line -1: error.**EDIT** I read it wrong. It said Line -1:, not Line: -1It crashes after 2 seconds...I wonder where that is. ControlCommand is a command right?can commands be used as umm.....forgot the term.. as a comparison? [whiles, ifs, do untils, !='s, other stoofs]$title = 'setup'Do Sleep(1000) WinActivate($title)Until WinActive($title)sleep(2000)Do Sleep(200)Until ControlCommand($title, , 'Button2', 'IsEnabled', '')ControlClick($title, "", "[CLASS:Button; INSTANCE:2]") Edited November 7, 2008 by RandomClown Link to comment Share on other sites More sharing options...
RandomClown Posted November 7, 2008 Author Share Posted November 7, 2008 (edited) OMG I found the problem!!command($title, , 'Button2', 'IsEnabled', '')**TO**command($title, '', 'Button2', 'IsEnabled', '')got to have the ''If you didnt know, use that to help other users in the future.W00T! Edited November 7, 2008 by RandomClown 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