Jump to content

PixelSearch... again


kim1234
 Share

Recommended Posts


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 by kim1234
Link to comment
Share on other sites

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 by Nine
Link to comment
Share on other sites

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...

Image1.jpg.0b6e2d903081b1ceb5bf44e5daf8c1d8.jpg 


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

Link to comment
Share on other sites

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 by Bert
Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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 by kim1234
Link to comment
Share on other sites

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 by kim1234
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...