First of all, if this intro is TLTR, goto “now comes the part where I call the cavalry.”
A short introduction before diving into my question. This helps you maybe a bit better what and why I am trying to achieve. In my mancave i have a few walls soundproofed. Through this soundproof runs a led setup with close to 2000 LED's, making this a led wall. This led wall is controlled by an app called WLED, and set-up in a way that i can control the patterns with HTTP GET requests for (home) automation purposes.
During my gaming sessions events are happening which I want to show on the wall for a bit extra immersion. Like getting shot during gameplay in shooters, the wall flashes red, or during a race game when the yellow flag comes out, the wall is blinking yellow. During police chases, the wall is flashing red and blue, well, you get the point.
To achieve all this, I could go for an UDP config, but not all the games support this option. So, I decided to interpret the color of specific pixels on the screen. My gaming screen is always the same screen and in the middle of my three screen setup. So based on this, I can define the pixel’s x and y position.
Now comes the part where I call the cavalry:
I use the code enclosed below. I need the code recognize that specific pixel when it has color code “F0F0F0”. After that, it has to check for the switch value Z. This value is important to avoid overload the WLED server to overload in HTTP requests.
To be precise: If the pixel contains the requested value AND the control is zero, Do stuff (the position of “msgbox, Found”. Also, when the pixel contains anything but the requested value AND the zero is 1, Do other stuff (the position of “msgbox, NotFound).
How this code handles until now: with the Tooltip lines I can confirm whether at the right time the right value is found by PixelGetColor, which is working fine. But, I cannot let the code understands that it needs to do stuff based on that value. I think I mismatched something somewhere, but as a started in AHK, I cannot oversee nor find it.
Code: Select all
#SingleInstance, Force
;x:=1878
;y:=31
;x:=2698
;y:=223
z=0
x:=1878
y:=31
color2check=F0F0F0
CoordMode,Pixel,screen
ToolTip, started
Loop
{
PixelGetColor,readpixelcolor,x,y,RGB
StringTrimLeft,readpixelcolor,readpixelcolor,2
;mousemove, x,y
If (readpixelcolor <> F0F0F0)
{
tooltip, %readpixelcolor% %z%
if (z == 1)
{
msgbox, NotFound
z = 0
}
}
If (readpixelcolor = F0F0F0)
{
tooltip, %readpixelcolor% %z%
if (z == 0)
{
msgbox, Found
z = 1
}
}
sleep, 100
tooltip,
}
Numpad0::
msgbox, exit
ExitApp