Pixel searching finding incorrect colour Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rubeusmalfoy
Posts: 27
Joined: 20 Sep 2023, 06:40

Pixel searching finding incorrect colour

29 Apr 2024, 10:37

I am testing a number of pixel searches and the below test keep registering on black (000000) or rather than the colour I'm searching for. With the variation set to missing (0) I would assume it's not that causing the issue. This seems to happen no matter what colour I have it search for.

Code: Select all

#Requires AutoHotkey v1.1.33.11
CoordMode, mouse, Screen
CoordMode, Pixel, Screen
F1::

Loop {
    pixelsearch, Bx, By, 550, 200, 1850, 1450, B97A57, , Fast RGB
    if (ErrorLevel = 0) {
        Msgbox RED found at coordinates: %Bx%, %By%
    }
    else {
        sleep 2000
    }
}
User avatar
gregster
Posts: 9224
Joined: 30 Sep 2013, 06:48

Re: Pixel searching finding incorrect colour  Topic is solved

29 Apr 2024, 10:42

You are not using the correct number format for hex numbers, starting with 0x:
https://www.autohotkey.com/docs/v1/lib/PixelSearch.htm#Parameters wrote:ColorID

The decimal or hexadecimal color ID to search for, by default in Blue-Green-Red (BGR) format, which can be an expression. Color IDs can be determined using Window Spy (accessible from the tray menu) or via PixelGetColor. For example: 0x9d6346.
Since colorID can be an expression, AHK v1 currently evaluates your color as a variable (which is probably blank = false = 0 = black color ID in decimal format).

https://www.autohotkey.com/docs/v1/Concepts.htm#numbers wrote:Numbers

AutoHotkey supports these number formats:
  • Decimal integers, such as 123, 00123 or -1.
  • Hexadecimal integers, such as 0x7B, 0x007B or -0x1.
  • Decimal floating-point numbers, such as 3.14159.
Hexadecimal numbers must use the 0x or 0X prefix, except where noted in the documentation. This prefix must be written after the + or - sign, if present, and before any leading zeroes. For example, 0x001 is valid, but 000x1 is not.
User avatar
mikeyww
Posts: 28869
Joined: 09 Sep 2014, 18:38

Re: Pixel searching finding incorrect colour

29 Apr 2024, 11:16

Also already here and with example! viewtopic.php?f=76&t=128557&p=569640#p569653

But good to have this additional explanation from gregster.

Some AHK commands use color strings without 0x, but the search commands do require the numeric format as shown.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 141 guests