Page 1 of 1

Trying to press keys based on color.

Posted: 10 May 2024, 21:00
by Twisting
Trying to get the computer to press keys based on the color at a certain coordinate. Red, green and blue work, but the first color, 161015, doesn't do anything. it should press key 1 and 2. Not sure what I am doing wrong here. This was edited from a script that was working in the past, but the color in that location has change so I had to edit the code. That seems to have broken the script.

Code: Select all

key := {0x161015: 12, 0x0000FF: 3, 0x00FF00: 1, 0xFF0000: 2}

[::
SetTimer, Spam, % (on := !on) ? 1000 : "Off"
SoundBeep, 1000 + 500 * on
Return

Spam:
PixelGetColor, bgr, 184, 711 ; Blue-green-red; coordinates relative to the active window
Send % key[bgr]
Return

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

Re: Trying to press keys based on color.

Posted: 11 May 2024, 04:04
by Rohwedder
Hallo,
try:

Code: Select all

key := {0x161015: 12, 0x0000FF: 3, 0x00FF00: 1, 0xFF0000: 2}

[::
SetTimer, Spam, % (on := !on) ? 1000 : "Off"
SoundBeep, 1000 + 500 * on
Return

Spam:
PixelGetColor, bgr, 184, 711 ; Blue-green-red; coordinates relative to the active window
Loop, Parse,% key[bgr]
	Send, {%A_LoopField%}
Return