Repeat command

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jessiebnyc
Posts: 2
Joined: 26 Jan 2023, 16:08

Repeat command

Post by Jessiebnyc » 26 Jan 2023, 16:13

I have a macro that is entirely image search and then click image. I have a problem though where sometimes a page loads slow. The macro will click the image when it appears, but since the page wasn't fully loaded then clicking the image doesn't do anything. This prevents the image in the next step from popping up so now the next step can't activate. I'm trying to either get step 1 to repeat if step 2 doesn't activate after x seconds or get step 1 to keep repeating until it's image is gone. I tried a "repeat until not found" command, but it isn't working. What's the best way to do this?

NewberEnerNeeder1
Posts: 47
Joined: 26 Mar 2019, 06:06

Re: Repeat command

Post by NewberEnerNeeder1 » 26 Jan 2023, 17:45

not sure what the best way is but what if you did one image search to find the target then when it finds the target wait sleep 2000 then have it search a 2nd time to find it and click it

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Repeat command

Post by mikeyww » 26 Jan 2023, 17:59

Welcome to this AutoHotkey forum!

There are also posts on this forum that show some different approaches to determining when the page has loaded.

User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Repeat command

Post by Xtra » 26 Jan 2023, 18:29

I'm trying to either get step 1 to repeat if step 2 doesn't activate after x seconds
You can try something like this: (change out the placeholders to what your code is.)

Code: Select all

Loop
{
    ImageSearch, image1X, image1Y, X1, Y1, X2, Y2, ImageFile1
	if (ErrorLevel = 0) {
		MouseClick, Left, image1X, image1Y    ; click image1
		Loop, 10    ; Allow upto 10 trys/seconds before clicking image1 again.
		{
			Sleep 1000			
			ImageSearch, image2X, image2Y, X1, Y1, X2, Y2, ImageFile2
			if (ErrorLevel = 0) {
				break, 2    ; break outer loop when 2nd image is found.
			}
		}
	}
}

Jessiebnyc
Posts: 2
Joined: 26 Jan 2023, 16:08

Re: Repeat command

Post by Jessiebnyc » 26 Jan 2023, 19:09

NewberEnerNeeder1 wrote:
26 Jan 2023, 17:45
not sure what the best way is but what if you did one image search to find the target then when it finds the target wait sleep 2000 then have it search a 2nd time to find it and click it
I've added a delay to give the page time to load, but sometimes it's especially slow and that delay isn't good enough. This is a macro I have run on repeat so having an over 5 second delay there every time really slows it down in the long run.

NewberEnerNeeder1
Posts: 47
Joined: 26 Mar 2019, 06:06

Re: Repeat command

Post by NewberEnerNeeder1 » 26 Jan 2023, 22:12

Jessiebnyc wrote:
26 Jan 2023, 19:09
NewberEnerNeeder1 wrote:
26 Jan 2023, 17:45
not sure what the best way is but what if you did one image search to find the target then when it finds the target wait sleep 2000 then have it search a 2nd time to find it and click it
I've added a delay to give the page time to load, but sometimes it's especially slow and that delay isn't good enough. This is a macro I have run on repeat so having an over 5 second delay there every time really slows it down in the long run.
maybe just image search something that fully loads on the page THEN once that thing loads have it search for the main search

Post Reply

Return to “Ask for Help (v1)”