Scan Pixel for Color while Key is held, then forcibly raise said key.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ammendment
Posts: 2
Joined: 01 Jun 2023, 14:54

Scan Pixel for Color while Key is held, then forcibly raise said key.

Post by ammendment » 01 Jun 2023, 14:58

I'm trying to make a script, that while a key is held, it searches for a color at a pixel, then sends an "up" for that key once it finds it. Any idea on how to make this work? It seems simple but so far has not been working. Here's the code.

Code: Select all

While GetKeyState, E [, P]
	{
	PixelGetColor, color, 1508, 641
	If (color = 563E76)
		Send, E Up
}

[Mod action: Moved topic to v1 section. The main section is for v2.]

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

Re: Scan Pixel for Color while Key is held, then forcibly raise said key.

Post by mikeyww » 01 Jun 2023, 19:20

Welcome to this AutoHotkey forum!

You are posting in the v2 forum.

Did you write this script? Where did you find this example?

Code: Select all

Send, E Up
I recommend examining examples of the function syntax, so that you can correct the bugs.

GetKeyStateUP hotkey modifier

If needed, refer to the v1 documentation.

To refer to a hexadecimal number, you would typically precede it with 0x. Example

ammendment
Posts: 2
Joined: 01 Jun 2023, 14:54

Re: Scan Pixel for Color while Key is held, then forcibly raise said key.

Post by ammendment » 03 Jun 2023, 15:35

I wrote this script myself. I'm brand new to AHK. I tried to read up on some of the function syntax but I've got no clue where to start. Do you think you could write up an example so I could take a look at what a functional version of this script would be?

The idea is that when the user presses e, it will hold E until the color 0x563E76 is found at coordinates (1508, 641) then release the E key once it sees that the coordinates have that color.

Thanks!

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

Re: Scan Pixel for Color while Key is held, then forcibly raise said key.

Post by mikeyww » 03 Jun 2023, 16:05

I'm surprised, because it seems that you are working from an example, but it's unclear where that example would be.

Some ideas are below.

Code: Select all

#Requires AutoHotkey v1.1.33
target := 0x763E56 ; Blue-Green-Red
x      := 1508     ; Relative to active window
y      := 641

$e::
MouseMove x, y
Send {e down}
Loop {
 Sleep 50
 PixelGetColor bgr, x, y
 ToolTip % bgr
} Until (bgr = target)
Send {e up}
ToolTip
SoundBeep 1500
Return
Considerations:
1. Refer to the AHK documentation, because it contains examples of the commands.
2. As a new user, think about whether to use AHK v1 or v2, and why. AHK v1 is older and deprecated.
Attachments
rgb563E76.png
RGB 0x563E76
rgb563E76.png (320 Bytes) Viewed 261 times

Post Reply

Return to “Ask for Help (v1)”