Jump to content

I know there has to be a simple solution...


Recommended Posts

I'm not completely new to AutoIt, but I'm by no means a veteran. I've been wondering how to do this for months now; usually when I have problems with AutoIt I consult the help file or google. Thus far I've still been at a loss.

I'm trying to figure out how to end a loop when a certain condition (unrelated to the loop) changes.

This is essentially a dumbed down example of what I'm trying to do:

---------------------------------------------------------------------

$checksum = PixelChecksum(x1,y1, x2,y2)

While $checksum = PixelChecksum(x1,y1, x2,y2)

$abc = 0

Do

Send ("abcgefghijklmnopqrstuvwxyz")

$abc = $abc + 1

Until $abc = 100

WEnd

----------------------------------------------------------------------

*The coordinates aren't important.

What I want to do is halt the loop when the condition (my PixelChecksum) changes even if the loop hasn't fully completed.

Simply checking the PixelChecksum after each " Send ("abcgefghijklmnopqrstuvwxyz") " doesn't work for me because if the pixel area changes at "a" the loop won't be halted until after "z" has been sent. Also what I'm doing is much longer and complicated than that. I just want a way to halt it instantly.

Hope I explained this well enough =/

If you look at the example in Help for PixelChecksum, you will see a similarity to your script.

The coordinates are important. To stop the While -Wend loop the PixelChecksum for the top left corner of the screen must change.

When you run the script move a window to or from the top left 50x50 pixels. then the While loop will exit.

To avoid sending the alphebeth 100 times, I have scale your script down.

; Wait until something changes in the region 0,0 to 50,50

; Get initial checksum
$checksum = PixelChecksum(0,0, 50,50)

; Wait for the region to change, the region is checked every 100ms to reduce CPU load
While $checksum = PixelChecksum(0,0, 50, 50)

$abc = 0
Do

Send ("a")
$abc = $abc + 1

Until $abc = 5
sleep(100)
WEnd

Run, then move a desktop window from or into the top left corner of the desktop.

Link to comment
Share on other sites

Sure... get the PID when you launch it, and kill the PID when the condition occurs...

But I've not researched this, so you may need to check the help file for doing all that. Or maybe someone here has some quick pointers...?

First of all, I don't know what a PID is ='(. Program ID?? But if it were to work, this is actually exactly the solution I wanted. It's (fairly) easy, and it's general.

Link to comment
Share on other sites

If you look at the example in Help for PixelChecksum, you will see a similarity to your script.

The coordinates are important. To stop the While -Wend loop the PixelChecksum for the top left corner of the screen must change.

When you run the script move a window to or from the top left 50x50 pixels. then the While loop will exit.

To avoid sending the alphebeth 100 times, I have scale your script down.

; Wait until something changes in the region 0,0 to 50,50

; Get initial checksum
$checksum = PixelChecksum(0,0, 50,50)

; Wait for the region to change, the region is checked every 100ms to reduce CPU load
While $checksum = PixelChecksum(0,0, 50, 50)

$abc = 0
Do

Send ("a")
$abc = $abc + 1

Until $abc = 5
sleep(100)
WEnd

Run, then move a desktop window from or into the top left corner of the desktop.

I actually did try this. It worked when I moved a window, but when I just moved my cursor through the region it didn't halt the Send (""). I don't quite understand why either.

Link to comment
Share on other sites

PID = Process ID.

to get it...

dim $procID
$procID = run("sendstuff.exe")

then...

If Not (PixelChecksum(x1,y1, x2,y2) = $checksum) then
    ProceessClose($procID)
EndIf

Hope this works...

Link to comment
Share on other sites

PID = Process ID.

to get it...

dim $procID
$procID = run("sendstuff.exe")

then...

If Not (PixelChecksum(x1,y1, x2,y2) = $checksum) then
    ProceessClose($procID)
EndIf

Hope this works...

I'm awfully tired at the moment, but I'm pretty sure this is what I'm looking for.

Thank you and everybody else that helped me out, I learned a few things.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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