Detect if an area doesnt contain a pixel of a specific color ordetect a change

Ask gaming related questions (AHK v1.1 and older)
r3dnuht
Posts: 1
Joined: 12 Oct 2018, 13:58

Detect if an area doesnt contain a pixel of a specific color ordetect a change

13 Oct 2018, 05:21

Hi, I'm a complete beginner on Autohotkey. I have a loop that runs with a toggle and searches for a pixel of a specific color in an area. As long as the pixel is found I make a click at a precise coordinate, if it is not found I perform another action. Here is the script, I can't do the other action in case the color is not found.

Code: Select all

toggle := False

f1 UP::
toggle := !toggle

Loop {
    If (!toggle) {
            break
        }
PixelSearch, x, y, 1099, 390, 982, 411, C8C6A3, 10, fast RGB
     If (ErrorLevel = 0)
    {
        CoordMode, Mouse, Window
        MouseClick, Right, 1229, 397
        sleep 100
        CoordMode, Mouse, Window
        MouseClick, Left, 1482, 394
        sleep 100
        CoordMode, Mouse, Window
        MouseClick, Left, 1279, 300 
        sleep 150 
    }
     else ;
          {
            CoordMode, Mouse, Window
            MouseClick, Left, 1279, 300 
            sleep 150 
          }
}
Return
maybe if someone knows another approach, my goal is to detect a change in an area of pixels then perform one action with a loop, if a change is detected perform one action if not it loops. thanks for your help.
User avatar
PipeDreams
Posts: 165
Joined: 19 Dec 2015, 00:20

Re: Detect if an area doesnt contain a pixel of a specific color ordetect a change

14 Oct 2018, 04:19

Hello, I think you would be better off looking into loop timers if you want to run more then one loop. AHK can only run one loop at a time so if you wish to run many actions using loops you have to chain the loops together. Here’s an example.
Also, I’ve changed your PixelSearch a bit for the example, you can always change it to whatever you want.

Code: Select all

#SingleInstance Force
#Persistent


F1:: ;This is the hotkey.
Start: ;This is a GLable. It can be use as a timer, so this is also loop timer #one.
{	KeyWait, F1 ;This waits for F1 to come up.
	Running := !Running ;This is the toggle switch command.
	{	If Running
		{	SetTimer, GoManGo, 500 ;this is the command to use a GLabe as a Loop Timer.
			SoundBeep, 700, 50
		} Else, ;If NOT Running
		{	SoundBeep, 300, 75
		}
	}
} Return

GoManGo: ;This is loop timer #Two.
{	If Running
	{	MouseGetPos, X, Y
		PixelSearch, x, y, 668, 88, 954, 163, "0xFFFFFF", 10, fast RGB ;Your code 0xC8C6A3
		If (ErrorLevel = 0)
		{	SoundBeep, 700, 75
			ToolTip, Pixel Found!
			SetTimer, RemoveToolTip, -500
		} Else, 
		{	SoundBeep, 300, 75
		}
	} Else, 
	{	ToolTip, Paused From GoManGo Loop.
		SetTimer, RemoveToolTip, -2000 ;wait 1sec.
		Sleep, 1000
		SetTimer, GoManGo, OFF
	}
} Return


RemoveToolTip:
{	ToolTip
	SetTimer, RemoveToolTip, OFF
} Return


~Esc::ExitApp ;Kills the script!

And here’s a little tool I like to use for my pixel projects. It will record your mouse location and the pixel color to your clip board just by pressing the right mouse button. Then you just paste it into whatever you want.

Code: Select all

RButton::
While (GetKeyState("RButton", "P"))
{	PixelGetColor, Color, X, Y, RGB, Fast
	MouseGetPos, X, Y
	Clipboard := Color " PixelGetColor, Color," " "X ", "Y ", RGB Fast" ;OUTPUT = 0x00C2E4 PixelGetColor, Color, 976, 1005, RGB
	ToolTip, % "Clipboard Contains `nPixel Color = " Color " "  "`nPixel Location X" X "  Y" Y " "
	SetTimer, RemoveToolTip, -2000
} Return
RemoveToolTip:
{	ToolTip
} Return
~Esc::ExitApp ;Kills the script!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Shoobis and 43 guests