Jump to content

Recommended Posts

Posted

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? :whistle:

  • Administrators
Posted

Because after your for loop the Window is still active, which makes the WHILE true again and it starts again.


 

  • Administrators
Posted

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


 

Posted

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?

  • Administrators
Posted

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? :whistle:


 

  • Administrators
Posted

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.


 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...