Color is found (PixelGetColor) but loop does not end Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Pepineros
Posts: 45
Joined: 16 Apr 2018, 17:26
Location: Ireland

Color is found (PixelGetColor) but loop does not end

16 Apr 2018, 17:50

Hi all,

Hoping to get some help with what I'm sure is a silly user error.

I'm trying to get my script to wait for a specific color to pop up in a specific place before continuing. Pretty basic stuff to auto-load and login to websites. I'm getting the colour I'm expecting, it's picked up by the script, but the loop just keeps running instead of continuing.

My code so far:

Code: Select all

f9::
	send,^t		; open new tab
	WinWait,New tab - Internet Explorer		; wait for tab to become active
	send,https://url.com{enter}		; sending URL and enter
	PixelGetColor,color,886,391		; get color from screen and store in var "color" (original I know)
	While %color% != 0xECD4C6		; while color is not equal to expected value...
	{
		MsgBox I found %color% instead		; tell me what color was found (for testing purposes)
		Sleep,1000				; wait a second
		PixelGetColor,color,886,391		; get the color again and revalidate the while expression
	}
	send,{tab 6}{enter}		; once color is found, send the tabs and enter I need to continue
return
Every time I get the control message box, it says it found color 0xECD4C6 at the coordinates, but despite this the while loop is not ending. I have tried adding alt or slow to pixelgetcolor to no avail.

I have tried the same with a loop{ if color matches, execute tabs and break; if not, recheck color } with the same result.

What am I missing?

Thanks!
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: Color is found (PixelGetColor) but loop does not end

16 Apr 2018, 18:25

The While syntax is wrong, I think. While expects an expression.

Hence, use While (color != 0xECD4C6)
( While (color != "0xECD4C6") should also work. )
Pepineros
Posts: 45
Joined: 16 Apr 2018, 17:26
Location: Ireland

Re: Color is found (PixelGetColor) but loop does not end

16 Apr 2018, 21:12

Thanks gregster, same behaviour unfortunately.

Here's the loop I tried as well, with same result, just making sure the While isn't the problem. The MsgBoxes will not be part of the final script, they're just there so I know the loop is running.

Code: Select all

f9::
	send,^t		; open new tab
	WinWait,New tab - Internet Explorer		; wait for tab to become active
	send,https://url.com{enter}		; sending URL and enter
	PixelGetColor,color,886,391
	Loop
		{
		If(%color% = 0xECD4C6)    ; also tried "0xECD4C6" to no avail
			{
			MsgBox Found %color%!
			send,{tab 6}{enter}
			Break
			}
		else
			{
			MsgBox Not yet, found %color% instead
			PixelGetColor,color,886,391
			}
		}
return
Is there another way of checking whether a web page is loaded, apart from using Sleep? In this specific case I'm waiting for a hyperlink to become available on the page, so i guess I can just fire clicks at the coordinates of that link every 100ms until it hits, but that's only marginally better than using Sleep. I would much rather understand why my while or if loops are not working when they seem to be getting the correct color from the correct pixel.
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: Color is found (PixelGetColor) but loop does not end  Topic is solved

16 Apr 2018, 21:33

Your if syntax is wrong in the same way like your while syntax (put no %s around color in if-expression style!). In general, the COM approach works best in automating Internet Explorer: there are lots of examples on the forum - here is an (older) introduction: https://autohotkey.com/board/topic/6456 ... -webpages/
Pepineros
Posts: 45
Joined: 16 Apr 2018, 17:26
Location: Ireland

Re: Color is found (PixelGetColor) but loop does not end

16 Apr 2018, 22:24

You're a star! Totally missed the %s missing in your example. That did it. I knew it was a basic thing I missed...

Thank you!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Giresharu, RandomBoy and 184 guests