PixelSearch and MouseGetPos

Ask gaming related questions (AHK v1.1 and older)
bax
Posts: 2
Joined: 23 Jul 2020, 15:14

PixelSearch and MouseGetPos

23 Jul 2020, 15:35

I have been trying to solve this problem for about 1 day now and have come to the conclusion that I am missing something or I am just blind :D .

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 :D. Anyway, so please, I'm driving my self crazy over here :crazy:

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
Test Image:
test.png
test.png (112 Bytes) Viewed 977 times
===============Solution===============

Credit to Rohwedder! :D

This line:

Code: Select all

PixelSearch, Px, Py, %x1%, %y1%, %x2%, %y2%, 0x03065F, 10,RGB Fast
Needs to be:

Code: Select all

PixelSearch, Px, Py, %x1%, %y1%, %x2%, %y2%, 0x03065F, 10, Fast
Last edited by bax on 24 Jul 2020, 10:52, edited 4 times in total.
Rohwedder
Posts: 7645
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: PixelSearch and MouseGetPos

24 Jul 2020, 03:43

Hallo,
remove the "RGB" in the PixelSearch command. Your ColorID is BGR.
bax
Posts: 2
Joined: 23 Jul 2020, 15:14

Re: PixelSearch and MouseGetPos

24 Jul 2020, 10:50

Rohwedder wrote: Hallo,
remove the "RGB" in the PixelSearch command. Your ColorID is BGR.
That seems to be the problem! It is working flawlessly now, thank you so much :D

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 83 guests