Key press/tap when specific color pops up?

Ask gaming related questions (AHK v1.1 and older)
JacobMclain
Posts: 6
Joined: 27 Mar 2023, 00:35

Key press/tap when specific color pops up?

Post by JacobMclain » 27 Mar 2023, 00:43

Heya i've used AHK for a while but i'm not the best i must admit. I've used it for a bunch of different arcade games throughout the years, just copy pasting stuff my friends would show me to make my own scripts work :lol:
Now i have this game where you have to react to a blue line hitting a green zone, and i'd like to see some examples for how this could be done :)
I've tried with color coordinates and so on but i cannot seem to get it to work at all

this is what i've tried:

Code: Select all

CoordMode, Pixel, Relative
Z::								
							
loop {
PixelGetColor, color1, 6, 999		; blue
if(color1 = "0x8F732C")	            		; if blue (change hex code)
	send {space}				; press space
return
}
return									
X::ExitApp
-----------------------

Code: Select all

Z::
Loop 50
	{
		PixelSearch, x, y, 905, 704, 1008, 803, 0x8F732C
			If ErrorLevel = 0	
				Send, {Space}
}
return ; End

X::ExitApp
[Mod edit: [code][/code] tags added.]

heres a couple of screenshots of the color change:

https://i.imgur.com/UOv8BDK.png

https://i.imgur.com/COchopK.png

Any help is much appreciated.

User avatar
mikeyww
Posts: 26595
Joined: 09 Sep 2014, 18:38

Re: Key press/tap when specific color pops up?

Post by mikeyww » 27 Mar 2023, 08:07

Welcome to this AutoHotkey forum!

Your script is complicated. You can simplify it to troubleshoot. Find out what color is there. See if it matches your expectation. After it works, you can expand the script.

Code: Select all

#Requires AutoHotkey v1.1.33

x      := 6
y      := 199
target := 0x8F732C ; Blue-Green-Red

z::
WinGetActiveTitle title
MouseMove x, y
PixelGetColor Clipboard, x, y
MsgBox 64, % "Color at (" x ", " y ")", % "Window title = " title "`n`nBGR = " Clipboard
Return


JacobMclain
Posts: 6
Joined: 27 Mar 2023, 00:35

Re: Key press/tap when specific color pops up?

Post by JacobMclain » 27 Mar 2023, 14:28

by the way i don't think this will work since the "green zone" keeps moving around to different spots on the wheel so is there a way to maybe make it check the color within a specific area?

Thank you for replying :)

User avatar
mikeyww
Posts: 26595
Joined: 09 Sep 2014, 18:38

Re: Key press/tap when specific color pops up?

Post by mikeyww » 27 Mar 2023, 14:46

The command checks one pixel. A way to test:
1. When your green zone appears, use your computer to take a screenshot. Save it.
2. You can now display your static image to test your script. You will be able to determine whether you have the right coordinates & color.

Concepts:
1. By default, coordinates are relative to the active window.
2. By default, AHK v1 refers to colors in blue-green-red format, which is not necessarily the most common format used elsewhere.
3. Moving the mouse to where you think the target color is located is a way to confirm the location during testing.

JacobMclain
Posts: 6
Joined: 27 Mar 2023, 00:35

Re: Key press/tap when specific color pops up?

Post by JacobMclain » 27 Mar 2023, 14:58

alright it seems like theres a slight variation depending where on the wheel the blue line hits the zone.
I'd then need it to check a bunch of different possible variations of the color so it knows when to send the key press?
I honestly have no idea how to set that up, i'm a bit lost haha.

I just did one position and picked out 3 different pixels which resulted in:
0xBD983A, 0xBE993A and 0xBE993B

User avatar
mikeyww
Posts: 26595
Joined: 09 Sep 2014, 18:38

Re: Key press/tap when specific color pops up?

Post by mikeyww » 27 Mar 2023, 15:56

With :arrow: PixelSearch, you can search a region and also include a color variation. It's probably what you should test next.

JacobMclain
Posts: 6
Joined: 27 Mar 2023, 00:35

Re: Key press/tap when specific color pops up?

Post by JacobMclain » 27 Mar 2023, 16:29

something along the lines of this?

Code: Select all

Z::
Loop 50
	{
		PixelSearch, x, y, 905, 704, 1008, 803, 0xBE993B, 3, Fast
			If ErrorLevel = 0	
				Send, {Space}

		PixelSearch, x, y, 905, 704, 1008, 803, 0xBE993A, 3, Fast
			If ErrorLevel = 0	
				Send, {Space}

		PixelSearch, x, y, 905, 704, 1008, 803, 0x947832, 3, Fast
				If ErrorLevel = 0
				Send, {Space}
}
return

X::ExitApp
Last edited by joedf on 27 Mar 2023, 16:32, edited 1 time in total.
Reason: [code] tags

User avatar
mikeyww
Posts: 26595
Joined: 09 Sep 2014, 18:38

Re: Key press/tap when specific color pops up?

Post by mikeyww » 27 Mar 2023, 17:27

Yes-- especially if it works!

JacobMclain
Posts: 6
Joined: 27 Mar 2023, 00:35

Re: Key press/tap when specific color pops up?

Post by JacobMclain » 28 Mar 2023, 13:40

i can't get it to work unfortunately i think i need way more different colors for it to actually register one of them.
Hmm.

Thanks for the help tho mate :)

Post Reply

Return to “Gaming Help (v1)”