Detecting the colour green, and reacting to it

Ask gaming related questions (AHK v1.1 and older)
MrCheeseman
Posts: 4
Joined: 19 Jul 2017, 11:47

Detecting the colour green, and reacting to it

19 Jul 2017, 12:10

Hi, I want this to start searching for the colour green after I press the NumPad divide key. If the program cannot find the colour green, (I would like it to be as close to the RGB colour code provided, and within a few shades, anything slightly green) it will sleep 50. If it does find the colour green, it will press K, wait for 4 seconds, and then press Y. If I press NumPad divide, the program will exit.

The program is acting up and I am not sure why. It seems to not detect the colour green and detects other strange colours. If someone could help I would greatly appreciate it! :)

My monitor is 1080p resolution. The game is Grand Theft Auto 5, and is also running in 1080p.

Code: Select all

CoordMode, Pixel, Screen

$NumpadDiv::ExitApp

$NumpadMult::
 Loop
 {
 PixelSearch, OutputVarX, OutputVarY, 560, 1006, 906, 1031, 0x579456, 10, Fast
 if !ErrorLevel
   {
    send,k
    sleep,4000
    send,y
   }
 else
  sleep,50
 }
Thanks :D
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Detecting the colour green, and reacting to it

20 Jul 2017, 13:48

FYI the default mode for PixelSearch is Blue/Green/Red, whereas pretty much everything else (eg the utility you probably used to get 0x579456) uses Red/Green/Blue.
Add the RGB flag to the command like so: PixelSearch, OutputVarX, OutputVarY, 560, 1006, 906, 1031, 0x579456, 10, Fast RGB
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Detecting the colour green, and reacting to it

21 Jul 2017, 05:43

This is the test code I came up with when I worked on my idea, which is kind of similar to yours.

Code: Select all

SendMode Input
#NoEnv
#MaxThreadsperHotkey 1
SetBatchLines -1
CoordMode, Screen

Suspend

*e::
BreakLoop = 0
Loop,
{
if (BreakLoop = 1)
break
MouseGetPos, mX, mY
PixelSearch, nX, nY, mX - 150, mY - 150, mX + 150, mY + 150, 0x0000E5, 10, Fast
Soundbeep,400
Sleep,500
	if ErrorLevel
	Continue
		Soundbeep,500,500			
		Sleep,500
		Soundbeep,500,500	
			Loop
			{
			if (BreakLoop = 1)
			break
			MouseGetPos, mX, mY
			PixelSearch, nX, nY, mX - 150, mY - 150, mX + 150, mY + 150, 0x0000E5, 10, Fast
			Soundbeep,900,100
			if ErrorLevel
			break
			}
}


*e Up::
BreakLoop = 1
Return

*w::
MouseGetPos, nX, nY
PixelGetColor, color, %nX%, %nY%
if !ErrorLevel
MsgBox, Color is %color%
Return


*~CapsLock::
	Suspend
	Return

*RAlt::
Process, Close, AutoHotKey.exe
Capslock to activate script.
You can get any color value on the screen if you press w. If you press and hold e, you will hear the first loop beeps until your mouse pointer gets close to the color you need, then it starts sending the second loop and if you move mouse away from that color it starts the first loop again. releasing e stops the process.

You can easily modify this to what you need, just remember that you must run gta5 in window for this to work.
MrCheeseman
Posts: 4
Joined: 19 Jul 2017, 11:47

Re: Detecting the colour green, and reacting to it

09 Feb 2021, 15:27

Thank you guys much appreciated :)

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 71 guests