Jump to content

After ControlClick, how can I check the color of the clicked coordinate?


Go to solution Solved by ioa747,

Recommended Posts

Hi all. I have some code which uses ControlClick to click on a particular XY coordinate inside a control (see code below).  How can I now check the color of the clicked pixel?  If it is equal to COLOR-A, I'd like to execute some conditional code.

Using the Window Info tool, I can see that it records teh correct color of this position (0xFF0000; see screenshot below).

Thanks in advance.

 

AutoItSetOption('WinTitleMatchMode', 2)

ControlClick('ShareX - Editor menu', '', 'WindowsForms10.Window.8.app.0.1a52015_r6_ad11', '', 1, 875, 15
WinWaitActive("ShareX - Color picker")

 

image.thumb.png.b60be00ace4d2d28001166d58ecedca0.png

Link to comment
Share on other sites

OK thanks for that.  In my case, I have the XY coordinates of inside the control itself, not of the entire window.  Will I be able to use PixelGetColor with that?  I guess I use the hwnd parameter to do that?

Link to comment
Share on other sites

  • Jos locked this topic
  • Jos unlocked this topic

yes, you can use PixelGetColor for that, you can get the color when you calculate coordinates, please red https://www.autoitscript.com/autoit3/docs/functions/ControlGetPos.htm https://www.autoitscript.com/autoit3/docs/functions/AutoItSetOption.htm for PixelCoordMode and https://www.autoitscript.com/autoit3/docs/functions/PixelGetColor.htm, and after some calculations that suit your need: eg. win pos (if needed) + control pos + click pos or depending of your needs you can pull color from correct coordinates

 

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

@bogQOK thanks for that.  I'm comfortable doing arithmetic.  But I'm a bit new to this, so can you walk me through some things?  Based on the screenshot I posted above, Here is what I have so far (see code below). 

AutoItSetOption('WinTitleMatchMode', 2)
AutoItSetOption ( "PixelCoordMode" , 2)

Local $hWnd = ConsoleWrite(WinWait("ShareX - Image editor - 1920x938", "", 10) & @CRLF)
Local $hControl = ConsoleWrite(ControlGetHandle($hWnd, "", "WindowsForms10.Window.8.app.0.1a52015_r6_ad11") & @CRLF)

ConsoleWrite(Hex(PixelGetColor (875, 20, $hControl ), 6) & @CRLF)

The coordinates I pass to PixelGetColor are clearly incorrect.  And my PixelCoordMode could also be incorrect.  Thoughts on how to properly resolve?  I am not familiar with the coordinate system in use--does 0,0 correspond to the bottom left corner of the screen? My Window Info tool indicates that the control has a position of 0,0, which is throwing me off.

The final line should print the following to the console:  0xFF0000  But in my case, the following is printed to the console:

0x00350676

0x00000000

F0F0F0

 

FYI to log results, I've wrapped everything in ConsoleWrite, which is probably a bit sub-optimal, so apologies for that.  If you have tips on how to improve it, I'm all ears.  If not, I plan to address it soon 🙂

Edited by cag8f
Link to comment
Share on other sites

As far as i tested (and i may be wrong) the way that control is rendered i do not think you can get that color correctly all the time, or at all using pixelgetcolor.

If you elaborate on what is the point of getting that pixel fill color, and how it is set in the first place maybe someone can suggest alternative solution that does not involve control with pixelgetcolor. Like directly pulling color from saved image or something.

 

I may be wrong, autoit info tool is behaving strange on my pc at the moment. I think i have problem with windows 10 scale that is influencing info tool.

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

  • Solution

this is the PixelGetColor part

Local $hWnd = WinWait("ShareX - Editor menu", "", 3)
ConsoleWrite("$hWnd" & $hWnd & @CRLF)

Local $aWinPos = WinGetPos($hWnd)
ConsoleWrite("$aWinPos:" & $aWinPos[0] & ", " & $aWinPos[1] & ", " & $aWinPos[2] & ", " & $aWinPos[3] & @CRLF)

Local $hControl = ControlGetHandle($hWnd, "", "WindowsForms10.Window.8.app.0.1a52015_r6_ad11")
ConsoleWrite("$hControl=" & $hControl & @CRLF)

;MouseMove($aWinPos[0] + 875, $aWinPos[1] + 20)

Local $Color = Hex(PixelGetColor($aWinPos[0] + 875, $aWinPos[1] + 20), 6)
ConsoleWrite($aWinPos[0] + 875 & ", " &  $aWinPos[1] + 20)
ConsoleWrite(" $Color=" & $Color & @CRLF)

 

and this is my approach

ShareXMenu("Send", "r") ;Rectangle
ShareXMenu("Click", 843) ;Fill Color
;~ Or
;~ ShareXMenu("Click", "843") ;Fill Color

;----------------------------------------------------------------------------------------
Func ShareXMenu($sCommand, $sOption)
;~ https://getsharex.com/docs/keybinds#tools
;~ Image editor only
;~ Keybind  Description
;~ Hold middle click    Pan image
;~ Ctrl + Mouse wheel   Zoom centered on cursor
;~ Ctrl + +     Zoom in
;~ Ctrl + -     Zoom out
;~ Ctrl + 0     Reset zoom
;~ Ctrl + Alt + 0   Zoom to fit
;~ Enter    Close image editor and continue task with changes applied
;~ Right click / Space  Close image editor and continue task without apply changes
;~ Esc  Close image editor and cancel task
;~ Ctrl + S     Save image
;~ Ctrl + Shift + S     Save image as…
;~ Ctrl + Shift + C     Copy image to clipboard
;~ Ctrl + U     Upload image
;~ Ctrl + P     Print image
;~
;~ Tools
;~ Keybind  Description
;~ Send M   Select and move
;~ Send R   Rectangle
;~ Send E   Ellipse
;~ Send F   Freehand
;~ Send L   Line
;~ Send A   Arrow
;~ Send O   Text (Outline)
;~ Send T   Text (Background)
;~ Send S   Speech balloon
;~ Send I   Step
;~ Send B   Blur
;~ Send P   Pixelate
;~ Send H   Highlight
;~ Send C   Crop image
;~ Send X   Cut out
;~
;~ Click 843    Fill Color
;~ Click 814    Border Color

    ;window handle
    Local $hWnd = WinWait("ShareX - Editor menu", "", 3)
    Local $aWinPos = WinGetPos($hWnd)
    ConsoleWrite("$aWinPos:" & $aWinPos[0] & ", " & $aWinPos[1] & ", " & $aWinPos[2] & ", " & $aWinPos[3] & @CRLF)

    ;icon size
    Local Const $iSZ = $aWinPos[3] / 2 ; - 16

    Switch $sCommand
        Case "Send"
            ConsoleWrite("- Send:" & $sOption & @CRLF)
            Local $hParent = WinGetHandle("ShareX - Image editor")
            WinActivate($hParent)
            Sleep(100)
            Send($sOption)

        Case "Click"
            $sOption = Int($sOption)
            ConsoleWrite("- Click:" & $sOption & @CRLF)
            ControlClick($hWnd, "", "WindowsForms10.Window.8.app.0.1a52015_r6_ad11", "left", 1, $sOption, $iSZ)
            ;MouseMove($aWinPos[0] + $sOption, $aWinPos[1] + $iSZ)

    EndSwitch

EndFunc   ;==>ShareXMenu
;----------------------------------------------------------------------------------------

 

I know that I know nothing

Link to comment
Share on other sites

AutoIt uses different coordinate systems depending on the PixelCoordMode setting. In your code, you've set it to 2, which means relative to the active window. However, you're trying to retrieve the color from a specific control within the window. To do that, you should set PixelCoordMode to 0, which uses screen coordinates. Update the line AutoItSetOption("PixelCoordMode", 2) to AutoItSetOption("PixelCoordMode", 0).

I think the below should work, I don't have ShareX to test it. Test this and let us know? or you can use @ioa747 code.
 

AutoItSetOption("WinTitleMatchMode", 1)

Local $hWnd = WinWait("ShareX - Image editor - 1920x938", "", 10)
Local $hControl = ControlGetHandle($hWnd, "", "WindowsForms10.Window.8.app.0.1a52015_r6_ad11")

AutoItSetOption("PixelCoordMode", 0)
Local $aControlPos = ControlGetPos($hWnd, "", $hControl)

ConsoleWrite(Hex(PixelGetColor($aControlPos[0] + 875, $aControlPos[1] + 20), 6) & @CRLF)

 

Kind Regards
Skeletor

"Coffee: my defense against going postal."

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...