So I have a very simple program, how it should work is as follows
- When the hotkey is pressed (F9 or something) get the position of the mouse.
- Then PixelSearch an area around the mouse position, ie. 80pixel square around the mouse or something.
- Search for the specified color
- If the color is within the search area, say the color was found, else color was not found.
That's it. That is how the program is supposed to work.
Now how it works when I run it.
When I run the program and press the hotkey, it ALWAYS says no color was found. Even when a 200 by 200 pixel square around my cursor is nothing but the specified hex color.
I feel as if I am missing something very important and I just can't think of it. It may just be better for a fresh pair of eyes of someone who knows what they're doing to look at my code to see if there are any problems.
I've extensively looked through the documentation and other examples of people using PixelSearch and I still can't find a solution. I thought I would mention that I'm relatively new to AHK and really want to learn more, so if anyone would also like to give me any tips, please do . Anyway, so please, I'm driving my self crazy over here
I'm going to post my code and also a sample img of the color I'm looking for so if anyone wants to look through my code or test it:
Code:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance,force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
F9::
MouseGetPos, MouseX, MouseY
x1 := (MouseX-80)
y1 := (MouseY-80)
x2 := (MouseX+80)
y2 := (MouseY+80)
PixelSearch, Px, Py, %x1%, %y1%, %x2%, %y2%, 0x03065F, 10,RGB Fast
if ErrorLevel = 2
{
MsgBox, (%x1%, %y1%) (%x2%, %y2%) Something went wrong.
}
if ErrorLevel = 1
{
MsgBox, (%x1%, %y1%) (%x2%, %y2%) Color was not found.
}
if ErrorLevel = 0
{
MsgBox, (%x1%, %y1%) (%x2%, %y2%) Color was found.
}
return
Credit to Rohwedder!
This line:
Code: Select all
PixelSearch, Px, Py, %x1%, %y1%, %x2%, %y2%, 0x03065F, 10,RGB Fast
Code: Select all
PixelSearch, Px, Py, %x1%, %y1%, %x2%, %y2%, 0x03065F, 10, Fast