Need to get pixelcolor in a window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Permagrin
Posts: 22
Joined: 27 Oct 2015, 15:05

Need to get pixelcolor in a window

Post by Permagrin » 25 May 2022, 12:01

Hello all.

I have the need to use GetpixelColor on a specific window. Say x50 Y10 of a specific window like "ahk_exe testwin.exe"

I know this has something to do with coordmode but I am just nut understanding. I have searched around and not found what I am looking for.

I know one of you could whip this out in a second.

I appreciate the help!

Thanks!

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

Re: Need to get pixelcolor in a window

Post by mikeyww » 25 May 2022, 12:06

It's already done for you.

https://www.autohotkey.com/docs/commands/PixelGetColor.htm#ExBasic

You can WinActivate the window if needed, or CoordMode, Pixel.

Code: Select all

winTitle = ahk_exe testwin.exe
x = 50
y = 10
#If WinExist(winTitle)
F3::
WinActivate
MouseMove, x, y
PixelGetColor, bgr, x, y
MsgBox, 64, Color (BGR), Blue-Green-Red = %bgr%
Return
#If

Permagrin
Posts: 22
Joined: 27 Oct 2015, 15:05

Re: Need to get pixelcolor in a window

Post by Permagrin » 25 May 2022, 12:33

Thanks for the reply!

Is there a way for this to work without the Hotkey? I commented out F3:: and that broke it. I need to be able to read the color without user interaction.

Thanks again for your help.

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

Re: Need to get pixelcolor in a window

Post by mikeyww » 25 May 2022, 13:15

Code: Select all

winTitle = ahk_exe testwin.exe
x = 50
y = 10
If WinExist(winTitle) {
 WinActivate
 MouseMove, x, y
 PixelGetColor, bgr, x, y
 MsgBox, 64, Color (BGR), Blue-Green-Red = %bgr%
} Else MsgBox, 48, Error, Window not found.`n`n%winTitle%
Return

Post Reply

Return to “Ask for Help (v1)”