BlueScreen Posted March 9, 2004 Share Posted March 9, 2004 I want to perform a certain operation in a loop using "For" function but only if a certain window is active. $Iterations=1 WinActivate ("blablabla") While WinActive ("BlaBlaBla") For $Loop=1 To $Iterations Send ("abcd") Next Wend Why the "For" loop is not terminated after only 1 iteration? Link to comment Share on other sites More sharing options...
Administrators Jon Posted March 9, 2004 Administrators Share Posted March 9, 2004 Because after your for loop the Window is still active, which makes the WHILE true again and it starts again. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
BlueScreen Posted March 9, 2004 Author Share Posted March 9, 2004 Right. So how can I do it right? Link to comment Share on other sites More sharing options...
Administrators Jon Posted March 9, 2004 Administrators Share Posted March 9, 2004 What are you trying to do? Do you never want to send keystrokes to that window again after the first time (even though it will still be active)? Do you need the while loop or would an IF be correct? $Iterations=1 WinActivate ("blablabla") If WinActive ("BlaBlaBla") Then For $Loop=1 To $Iterations Send ("abcd") Next EndIf Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
BlueScreen Posted March 9, 2004 Author Share Posted March 9, 2004 Well, the "IF" is not good enoght. I want to send lots of text to a window but I'm afraid this window will not be in Focus and all the text will be entered elsewhere. So a "While" will give me the constant ability to stop sending the text in a case that the target window is not active. Get it? Link to comment Share on other sites More sharing options...
Administrators Jon Posted March 9, 2004 Administrators Share Posted March 9, 2004 Hmm, the If still looks OK for me based on that description.. Let's try this way: 1. How many times do you want to send the text? 2. What do you want to happen if the window loses focus? Stop the script? Wait until it's active again? MsgBox error? Nothing? Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
BlueScreen Posted March 9, 2004 Author Share Posted March 9, 2004 Well, I want to send the text 100 times, and when the window gets out of focus, I want the script to resume when the window gets back to focus... Link to comment Share on other sites More sharing options...
Administrators Jon Posted March 9, 2004 Administrators Share Posted March 9, 2004 WinActivate("blablah") For $Loop = 1 to 100 While Not WinActive("blablah") Sleep(10) Wend Send("abcd") Next Or you could have a line to force the window to be active during the for loop. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
BlueScreen Posted March 9, 2004 Author Share Posted March 9, 2004 10x, Jon. It is working well. 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