Jump to content

Screen coordinates to Control coordinates (and finding the right control)


LaNiZ
 Share

Recommended Posts

Ok, So I've been trying to turn absolute screen coordinates from my image search (Using the >Image Search Library by kangkeng) into local Control Coordinates. But I can't seem to get it to work.

The reason I want to turn the coordinates into control coordinates is because I want to use ControlClick instead of MouseClick.
Why? Because MouseClick occupies the mouse while ControlClick works without taking control of the mouse (Making it possible to work on the computer while the script does it's tasks).

The biggest problem I have with this is that the image moves, it does not have a static position (It moves within a list, If you press a list item it moves to that position) and I can't seem to find it with AU3Info (The program is basicly written in Java, so it's not a Windows Form).

I've been trying to make it work using a custom version of Sm0ke_N's >_MouseGetCtrlInfo Function (To atleast find the right control first, then translate the screen coordinates into control coordinates, but it does not seem to work =S):
 

Func _GetCtrlId2($posX, $posY, $Win = Null)

    If $Win == Null Then $Win = $SKWindow



    $WinPos = WinGetPos($Win)



    $classList = WinGetClassList($Win)

    $controlList = StringSplit(StringTrimRight($classList, 1), @LF)



    For $iCount = UBound($controlList) - 1 To 1 Step - 1

        Local $nCount = 0

        While 1

            $nCount += 1

            Local $aCtrlPos = ControlGetPos($Win, "", $controlList[$iCount] & $nCount)

            If @error Then ExitLoop



            Local $Data

            Local $CtrlPos = ControlGetPos($Win, "", $controlList[$iCount] & $nCount)

            If Not FindCtrlCoords($controlList[$iCount] & $nCount, $Data) Then ExitLoop

            ConsoleWrite("CtrlPos2: " & $Data[0] & "," & $Data[1] & " : " & $Data[2] & ", " & $Data[3] & @CRLF)

            If $posX >= $Data[0] And $posX <= ($Data[0] + $Data[2]) _

                 And $posY >= $Data[1] And $posY <= ($Data[1] + $Data[3]) Then

                

                Return ControlGetHandle($Win, "", $controlList[$iCount] & $nCount)

                

            EndIf



        WEnd

    Next

    Return ''

EndFunc

I'm not sure what to do anymore.. Anyone have an idea how to proceed?

Edited by LaNiZ
Link to comment
Share on other sites

If you can find the controlID/handle of the control, you can use that to click it. ControlClick doesn't require the x and y position of the control. Also, the x and y parameters are the position inside the bounds of the control not the window or the screen coordinates.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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