Sending input when pixel color changes at a specific location

Ask gaming related questions (AHK v1.1 and older)
thistlewhistle
Posts: 1
Joined: 19 Jan 2022, 23:29

Sending input when pixel color changes at a specific location

Post by thistlewhistle » 19 Jan 2022, 23:53

I am rather new to AHK, but I have been digging all night through forums trying to piece together different scripts for my needs with no luck, maybe someone can help show me how to build it properly.

What I am trying to do is: When a pixel is equal to a specific color at a certain coordinate on screen, send an input, (or alternatively, mouse click on that same coordinate).

In best case scenario, and I'm not sure this is possible, but I would prefer this script to loop while holding a key, and when I am done holding a key it stops looping until I press it again. Otherwise, just a key that loops the script for 5 seconds per pressing would be a fine alternative.

I basically tried a bunch of variations using PixelGetColor and Window Spy.

I have a couple issues, one is that the input is sent into the active window I desire, even though I am in that window actively, not full screen, using the coordinates from Window Spy. However, if I alt-tab or click into my second monitor, I could see AHK spamming the input on my desktop, but if I clicked back in the window I desire it to work inside of, it was not sending any input. Do I have to somehow specify the specific window where to send the input? The other issue is it doesn't seem to care that the color was not equal to what I defined at those coordinates - it would just send the input infinitely the second I ran the script until I closed AHK.

So basically, best case, I want to hold a key such as the letter F. It looks for color 0xInsertHere at the X Y coordinates of a specific active window, and if that color is there, it sends the input once (or clicks on those coordinates).
Last edited by gregster on 19 Jan 2022, 23:54, edited 1 time in total.
Reason: Topic moved from 'Scripts and Functions > ...'.

Return to “Gaming Help (v1)”