kim1234 Posted February 22, 2019 Posted February 22, 2019 (edited) Hi guys, I know this topic has numerous threads but I can't see an answer to my problem. I am using PixelSearch to find a red square in a client window. It works but I don't understand the positioning. I have pixel coord mode set to 2 (position in client window). But... the location of the red box seems to be affected by where I have the parent window positioned, which doesn't make sense. Why should the position change when I am not changing anything but the parent window position if I am looking in the client window space? Also, when I position the mouse to what I expect the location should be in the client space, it correctly moves to the top left of the red area, but PixelSearch returns different coordinates to where the mouse is positioned. Here's a couple of test result examples, note I have not changed the window size, only its on-screen position: X-Pos Y-Pos PosWidth PosHeight ClientWidth ClientHeight PixelX PixelY 74 9 656 485 640 446 132 61 113 10 656 485 640 446 191 62 Here's my code, any suggestions would be gratefully received: Local $aWinGetPos, $aWinGetClientSize, $aPixelSearch Opt("PixelCoordMode", 2) ;1=absolute, 0=relative, 2=client Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client WinActivate("Test Window") $aWinGetPos = WinGetPos("Test Window") $aWinGetClientSize = WinGetClientSize("Test Window") PixelSearch(0, 0, 200, 200, 0xFF0000) ConsoleWrite($aWinGetPos[0] & @TAB & $aWinGetPos[1] & @TAB & $aWinGetPos[2] & @TAB & $aWinGetPos[3] & @TAB _ & $aWinGetClientSize[0] & @TAB & $aWinGetClientSize[1] & @TAB & _ $aPixelSearch[0] & @TAB & $aPixelSearch[1]) Regards Kim Edited February 22, 2019 by kim1234
AutoBert Posted February 23, 2019 Posted February 23, 2019 Is your "ClientWindow" Client in a other Window, and this parent is recognized by AutoIt? And ... again, what's the name of the app? As there are (most times) better solutions possible, PixelSearch and MouseClick is ugly ,causing errors.
Nine Posted February 23, 2019 Posted February 23, 2019 (edited) Tested with this code on Paint : Opt ("MustDeclareVars", 1) Local $aWinGetPos, $aWinGetClientSize, $aPixelSearch Opt("PixelCoordMode", 2) ;1=absolute, 0=relative, 2=client Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client Local $hWnd = WinActivate("[CLASS:MSPaintApp]") WinWaitActive ($hWnd,"",10) $aWinGetPos = WinGetPos($hWnd) $aWinGetClientSize = WinGetClientSize($hWnd) $aPixelSearch = PixelSearch(0, 0, 200, 200, 0xEF1C21) If @error then Exit MsgBox ($MB_SYSTEMMODAL,"","Pixel not found") MsgBox (0,"",$aWinGetPos[0] & @TAB & $aWinGetPos[1] & @TAB & $aWinGetPos[2] & @TAB & $aWinGetPos[3] & @CRLF & _ $aWinGetClientSize[0] & @TAB & $aWinGetClientSize[1] & @CRLF & _ $aPixelSearch[0] & @TAB & $aPixelSearch[1]) As you can see it works perfectly with 2 different locations. I changed your code to make it runable... Edited March 31, 2023 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
kim1234 Posted February 23, 2019 Author Posted February 23, 2019 Thanks for your help but... doesn't work for me! I copy/pasted your code (shown below) and changed the colour to 0xFF (red) but other than that its the same. The red box comes out in different positions when I move the parent window. Confused... Func _DoTest() Opt ("MustDeclareVars", 1) Local $aWinGetPos, $aWinGetClientSize, $aPixelSearch Opt("PixelCoordMode", 2) ;1=absolute, 0=relative, 2=client Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client Local $hWnd = WinActivate("[CLASS:MSPaintApp]") WinWaitActive ($hWnd,"",10) $aWinGetPos = WinGetPos($hWnd) $aWinGetClientSize = WinGetClientSize($hWnd) $aPixelSearch = PixelSearch(0, 0, 500, 500, 0xFF0000) If @error then Exit MsgBox ($MB_SYSTEMMODAL,"","Pixel not found") MsgBox (0,"",$aWinGetPos[0] & @TAB & $aWinGetPos[1] & @TAB & $aWinGetPos[2] & @TAB & $aWinGetPos[3] & @CRLF & _ $aWinGetClientSize[0] & @TAB & $aWinGetClientSize[1] & @CRLF & _ $aPixelSearch[0] & @TAB & $aPixelSearch[1]) Exit EndFunc
Bert Posted February 23, 2019 Posted February 23, 2019 (edited) and why do you need to search for a red square? why not just hook into the control directly? Also does this red square move around on the screen or is it in the same spot all the time? Requested a moderator to review this thread. Edited February 23, 2019 by Bert The Vollatran project My blog: http://www.vollysinterestingshit.com/
Nine Posted February 23, 2019 Posted February 23, 2019 @kim1234 What version of autoit do you have ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
kim1234 Posted February 23, 2019 Author Posted February 23, 2019 I am running AutoIT v3.3.14.2 and SciTE 3.7.3 Thanks for your attention.
kim1234 Posted February 23, 2019 Author Posted February 23, 2019 For reference, the background to this is I'm trying to use AutoIT to detect motion in a video stream and do something on the basis of it. Yes I know there are many, and better, ways to do that. In fact my video stream (security camera) has built in motion detection capability. But that's not the point, the point for me is the intellectual challenge of doing it with AutoIT. That's also not the point though, the point in this thread is that something is happening which I don't understand and I want to solve it. Hope that makes sense :-) Kim
Nine Posted February 23, 2019 Posted February 23, 2019 upgrade to latest version. v3.3.14.5. upgrade scite full version also. try again. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
kim1234 Posted February 24, 2019 Author Posted February 24, 2019 (edited) Both AutoIT and scite upgraded to latest version. No impact, issue remains, moving the parent window results in a different location for something in the client window. I don't know if it's relevant but this time I didn't put a red box on the client space, I simply filled the whole client background with red. But the problem still occurred. Edited February 24, 2019 by kim1234
kim1234 Posted February 24, 2019 Author Posted February 24, 2019 (edited) OK found out what was happening - windows screen scaling. I have mine set to 250% (very hi-def monitor). When I set it to 100% scaling the pixel search returned the same position no matter where the parent window was. Still a little puzzled in that, although I had set the full background to red the pixel position returned was 332, 63 rather than what I would have expect, 0,0. Also a little puzzled that the mouse position worked in spite of the screen scaling. Does AutoIT have a method for getting current screen scaling? Edited February 24, 2019 by kim1234
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