PixelSearch not finding a color that is there.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
humanbean
Posts: 1
Joined: 01 Oct 2022, 09:27

PixelSearch not finding a color that is there.

Post by humanbean » 01 Oct 2022, 09:41

Tl;dr: PixelSearch not finding a color that is there.

Hello! I am using PixelSearch in conjunction with MouseClick to click a color. Here is my garbage code:

Code: Select all

outer:
Loop
{
Loop
{
PixelSearch, x, y, 105, 25, 2000, 400, 0x4BB8F0, 2, Fast 
         If ErrorLevel 
                break
         else 
                 MouseClick, L, %x%, %y%
		 MouseClick, L, 755, 450
Sleep, 5
}
Loop
{
PixelSearch, x, y, 100, 100, 9999, 9999, 0x255C78, 2, Fast 
         If ErrorLevel
                break
         else 
                 continue_outer:
Sleep, 50
}
Loop
{
PixelSearch, x, y, 1063, 327, 9999, 9999, 0x0D8D0D, 2, Fast 
         If ErrorLevel 
                break
         else 
                 MouseClick, L, %x%, %y%
Sleep, 50
}
Loop
{
PixelSearch, x, y, 1110, 387, 9999, 9999, 0x00FF00, 3, Fast 
         If ErrorLevel 
                break
         else 
                 MouseClick, L, %x%, %y%
Sleep, 50
}
}

;
$Enter::
   ExitApp
return
Sorry, it's long and inefficient, and I will make it pretty - right after I fix this issue.
If you look at the first PixelSearch - 0x4BB8F0. It just doesn't work. Like, it returns a value and breaks the loop. But the color is on the screen, and in the search area. I am 100% certain. All of the other ones work, (well, I haven't tested 0x255C78 and it is in the same area, so it may fall to the same issue). Please help!

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

Re: PixelSearch not finding a color that is there.

Post by mikeyww » 01 Oct 2022, 10:50

Welcome to this AutoHotkey forum!

Debugging is easy, because you can use :arrow: PixelGetColor to determine the actual color, in Blue-Green-Red format.

Coordinates are relative to the active window. You can MouseMove to the coordinates where you believe that the color is present.

Code: Select all

x = 105
y = 25
MouseMove, x, y
PixelGetColor, bgr, x, y
WinGetActiveTitle, title
MsgBox, 64, Color, Active: %title%`n`nBGR = %bgr%

Post Reply

Return to “Ask for Help (v1)”