Trying to get get pixelgetcolor to work with pressing keys

Ask gaming related questions (AHK v1.1 and older)
Kachigga
Posts: 2
Joined: 21 Jun 2021, 01:46

Trying to get get pixelgetcolor to work with pressing keys

21 Jun 2021, 01:59

Hello, am farely new to AHK and im trying to make it so AHK constantly searches the screen for a certain pixel color, 0xF6E6A4. When it does not find this pixel color, I would like it to press 2(hotkey for item in game). Id like it do all of this while pressing A and D so my character moves back and forth. So far, the problem is that, when I press f9 to start the script. My character moves which is good, but it does not press 2 until I press f9 again, at that time it spams 2. to TLDR, the goal is to spam A and D, while searching for a color on my screen, if it doesnt exist pressing 2.

Code: Select all


F6:: 
Reload
Return


f9::
Toggle := !Toggle
Loop
{
	If (!Toggle)
		Break
	Send A
	Sleep 200
	Send D
	Sleep 200
	
}

Loop
{
	PixelGetColor, color, 332, 31, RGB
	if (color != #f6e6a2)
		Send 2
	
}
}
Rohwedder
Posts: 7625
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Trying to get get pixelgetcolor to work with pressing keys

21 Jun 2021, 03:07

Hallo,
only a try:

Code: Select all

F6::Reload
F9::SetTimer, TF9,% (TF9:=!TF9)?200:"Off"
TF9: ;every 200ms, On/Off with F9
Send,% (AD:=!AD)?"A":"D" ;alternately A or D
PixelGetColor, color, 332, 31, RGB
if (color != #f6e6a2)
	Send 2
Return
Kachigga
Posts: 2
Joined: 21 Jun 2021, 01:46

Re: Trying to get get pixelgetcolor to work with pressing keys

21 Jun 2021, 03:55

Hey, appreciate the response a ton. The problem im running into with what youve composed is that I guess its not recognizing the color. I can post examples real quick. So when the icon indicated by the red arrow is gone, is when id like it to press 2. Now originally, the color in the script is in the middle of that icon, the kind of skin color you see. With the one you posted, I dont think its recognizing the color or maybe my cords are wrong, will keep testing.
image.png
image.png (9.06 KiB) Viewed 406 times
Rohwedder
Posts: 7625
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Trying to get get pixelgetcolor to work with pressing keys

21 Jun 2021, 04:23

See https://www.autohotkey.com/docs/commands/PixelSearch.htm
ColorID: The decimal or hexadecimal color ID to search for, in Blue-Green-Red (BGR) format.
Color IDs can be determined using Window Spy (accessible from the tray menu) or via PixelGetColor. For example: 0x9d6346.

I replaced #f6e6a2 by 0xf6e6a2 and added a tooltip to test it.

Code: Select all

F6::Reload
F9::SetTimer, TF9,% (TF9:=!TF9)?200:"Off"
TF9: ;every 200ms, On/Off with F9
Send,% (AD:=!AD)?"A":"D" ;alternately A or D
PixelGetColor, color, 332, 31, RGB
ToolTip,% color "`nLine: " A_LineNumber
if (color != 0xf6e6a2)
	Send 2
Return
In my scripts, all test tooltips also show the script line. Finding a forgotten tooltip in a big script sucks!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 98 guests