cag8f Posted June 7, 2023 Share Posted June 7, 2023 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") Link to comment Share on other sites More sharing options...
Skeletor Posted June 7, 2023 Share Posted June 7, 2023 PixelGetColor Returns a pixel color according to x,y pixel coordinates. Kind RegardsSkeletor "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 More sharing options...
cag8f Posted June 7, 2023 Author Share Posted June 7, 2023 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 More sharing options...
bogQ Posted June 7, 2023 Share Posted June 7, 2023 (edited) 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 June 7, 2023 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) 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 More sharing options...
cag8f Posted June 7, 2023 Author Share Posted June 7, 2023 (edited) @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 June 7, 2023 by cag8f Link to comment Share on other sites More sharing options...
bogQ Posted June 7, 2023 Share Posted June 7, 2023 (edited) 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 June 7, 2023 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) 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 More sharing options...
Solution ioa747 Posted June 7, 2023 Solution Share Posted June 7, 2023 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 expandcollapse popupShareXMenu("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 More sharing options...
ioa747 Posted June 8, 2023 Share Posted June 8, 2023 7 hours ago, bogQ said: I think i have problem with windows 10 scale that is influencing info tool. take a look if help 210297-problems-with-4k-3840%C3%972160-resolution/#comment-1518959 I know that I know nothing Link to comment Share on other sites More sharing options...
Skeletor Posted June 8, 2023 Share Posted June 8, 2023 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 RegardsSkeletor "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 More sharing options...
cag8f Posted June 8, 2023 Author Share Posted June 8, 2023 @ioa747 @Skeletor Thank you both for that--you went above and beyond 🙂 Both sets of code did exactly what I want. And I now have a much better understanding of the coordinate systems used. We can consider this resolved. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now