Trying to press keys based on color.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Twisting
Posts: 3
Joined: 04 May 2022, 19:55

Trying to press keys based on color.

Post by Twisting » 10 May 2024, 21:00

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.]
Rohwedder
Posts: 7718
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Trying to press keys based on color.

Post by Rohwedder » 11 May 2024, 04:04

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
Post Reply

Return to “Ask for Help (v1)”