Jump to content
Sign in to follow this  
tfabris

Please help? ControlGetPos is giving me the wrong position, different from Au3Info.exe

Recommended Posts

tfabris
Please help! 
 
I am using Autoit version 3.3.10.2 to automate a task where I need to click on a control on a window of a third party program. I am having a problem with the ControlGetPos function. When I call it with the correct information about the contol and its parent window, it reports the wrong value for the Y position, though the X position is correct.
 
When I run AU3INFO.EXE it reports the correct position, though. Please see the attached screen shot to understand what I mean.
 
 
post-72839-0-22888900-1406232387_thumb.p
 
 
Here is the source code for the example code that I am running in the attached screen shot. These are the only two lines in my example program, for simplicity (it assumes the window is already up on the screen in this example):
 
 
$ControlCoordinates = ControlGetPos("Diagnostic Report", "", "[NAME:m_Details]")
MsgBox(0, "Output from my AutoIt Test Script", "Autoit code believes the control to be at this location: " & @CRLF & $ControlCoordinates[0] & "," & $ControlCoordinates[1])

(Note: I have tried putting Opt("MouseCoordMode", 2) at the top of the code and it does not change the value, regardless of whether I do 0, 1, or 2 for the mode.)

 

As you can see from the screen shot, AutoIt is getting "140" for the Y position. But the same control, when use AU3INFO.EXE to obtain its location, reports 164 for the Y position.

I'm sure we're talking about the same control here. When I hover over the control with AU3INFO.EXE it reports the name "[NAME:m_Details]" for that control, and that is what I put into the code. There are no other controls on the window with that identifier, it is unique to that control in the example I have shown.

The reason this is a problem is that I need to send a MouseClick to that place on the screen (ControlClick doesn't work for this program, I don't know why) and with MouseClick it's imperative that I get the position correct. It's not coming out correct this way and the mouse is clicking 24 pixels too high to register.

What's wrong with the ControlGetPos function, and more importantly, why does AU3INFO.EXE get it right when it was written by the same people? What is AU3INFO doing right that AutoIt's ControlGetPos function is not doing right? How can I fix this so my code works correctly in all cases?

 

 

Share this post


Link to post
Share on other sites
tfabris

I also tried changing the code to:

$ControlCoordinates = ControlGetPos("Diagnostic Report", "", "[TEXT:Show details]")

And it does the same thing, getting the incorrect "140" instead of the correct "164" for the position.

Share this post


Link to post
Share on other sites
tfabris

Also, I can tell it is not messing up based on the windows title bar size. If it were, the number would be in the 200s, not 164 or 140.

For instance, if a take the screen shot and crop it down to just the client area rectangle of the window, then the control sits pretty much exactly at 116,164 as AU3INFO says it should.

Share this post


Link to post
Share on other sites
Jos

What is returned for Width and Height for these functions: WinGetClientSize() and WinGetSize()  ?

Jos

edit: there is no need to keep on adding posts to your thread. ;)

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
tfabris
What is returned for Width and Height for these functions: WinGetClientSize() and WinGetSize() ?

 

 

I could not find a WinGetSize function so I used the width and height of WinGetPos instead, I'm hoping that's what you meant. Note that in this run, I show a screen shot where the window I'm working with is a different position and size than I showed in my last example. But I get the same basic problem (and the same answers) no matter what size or position the window occupies on the screen.

 

Updated screen shot and code:

$ControlCoordinates = ControlGetPos("Diagnostic Report", "", "[TEXT:Show details]")
$WinGetClientSize = WinGetClientSize("Diagnostic Report")
$WinGetPos = WinGetPos("Diagnostic Report")
MsgBox(0, "Output from my AutoIt Test Script", "Autoit code believes the control to be at this location: " & @CRLF & $ControlCoordinates[0] & "," & $ControlCoordinates[1] & @CRLF & @CRLF & $WinGetClientSize[0] & "," & $WinGetClientSize[1] & "<- Client Size" & @CRLF & $WinGetPos[2] & "," & $WinGetPos[3] & "<- Get Pos")


WinActivate("Diagnostic Report")
Opt("MouseCoordMode", 0)   ; This is actually WORSE if I do window-relative (0) instead of client-area-relative (2).
MouseMove ($ControlCoordinates[0], $ControlCoordinates[1], 0)

post-72839-0-93779900-1406239546_thumb.p

 

The difference in the Y direction betwen WinGetClientSize and WinGetPos is 45. This difference is the same no matter where on the screen the window is, or what size it is, when I run it, the difference is always 45.

Not sure if that's relevant though. For example, if I add the code in (shown above now) to move the mouse to the upper left corner of that control, if I do it Window-relative (MouseCoordMode =0) instead of ClientArea-relative (MouseCoordMode =2), then it's actually WORSE that way, with the pointer being even higher up on the screen than it should be.

Interesting note!:

I just got done writing a bunch of C# code which tried to do the same thing using the API functions GetWindowRect and MapWindowPoints. Guess what? That code got the same answer as the AutoIt script got! In other words, the wrong answer of 116,140.

So what is AU3INFO doing that's special, that gets the answer more right than either AutoIt or GetWindowRect/MapWindowPoints?

 

EDIT: 

Updated information: This seems to be related to the number of lines of text which appear in the box along with the "Show details" link. (The example screen I have shown can have different numbers of lines of summary text in the box before the link I'm trying to click on.)

If there are more lines of text in the box, then the error between where it should be clicking and where it is clicking, is even greater. 

Edited by tfabris

Share this post


Link to post
Share on other sites
tfabris

Simplespy puts out 218;290 for the bounding rectangle of the object I'm after. However I think those were absolute screen coordinates, not window-relative coordinates, and I don't see the window's screen position in the output so I don't know where to do the math to get the window-relative coordinates in this case. Here is the full output:

Mouse position is retrieved 279-300
At least we have an element [Show details][]
Having the following values for all properties: 
Title is: <Show details> Class   := <> controltype:= <UIA_HyperlinkControlTypeId> ,<50005> , (0000C355) 
*** Parent Information top down ***
7: Title is: <Desktop> Class   := <#32769> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 
"Title:=Desktop;controltype:=UIA_PaneControlTypeId;class:=#32769" 
6: Title is: <Diagnostic Report> Class   := <WindowsForms10.Window.8.app.0.33c0d9d> controltype:= <UIA_WindowControlTypeId> ,<50032> , (0000C370) 
"Title:=Diagnostic Report;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d" 
5: Title is: <> Class   := <WindowsForms10.Window.8.app.0.33c0d9d> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 
"Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d" 
4: Title is: <> Class   := <WindowsForms10.Window.8.app.0.33c0d9d> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 
"Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d" 
3: Title is: <> Class   := <WindowsForms10.Window.8.app.0.33c0d9d> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 
"Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d" 
2: Title is: <> Class   := <WindowsForms10.Window.8.app.0.33c0d9d> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 
"Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d" 
1: Title is: <Status> Class   := <WindowsForms10.Window.8.app.0.33c0d9d> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 
"Title:=Status;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d" 
0: Title is: <Show details> Class   := <WindowsForms10.STATIC.app.0.33c0d9d> controltype:= <UIA_TextControlTypeId> ,<50020> , (0000C364) 
"Title:=Show details;controltype:=UIA_TextControlTypeId;class:=WindowsForms10.STATIC.app.0.33c0d9d" 
*** Standard code ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP6=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Diagnostic Report;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d", $treescope_children) 
_UIA_Action($oP6,"setfocus")
Local $oP5=_UIA_getObjectByFindAll($oP6, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d", $treescope_children) 
_UIA_Action($oP5,"setfocus")
Local $oP4=_UIA_getObjectByFindAll($oP5, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d", $treescope_children) 
_UIA_Action($oP4,"setfocus")
Local $oP3=_UIA_getObjectByFindAll($oP4, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d", $treescope_children) 
_UIA_Action($oP3,"setfocus")
Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d", $treescope_children) 
_UIA_Action($oP2,"setfocus")
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=Status;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.33c0d9d", $treescope_children) 
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Show details;controltype:=UIA_TextControlTypeId;class:=WindowsForms10.STATIC.app.0.33c0d9d", $treescope_children) 
_UIA_Action($oP0,"setfocus")
;~ First find the object in the parent before you can do something
;~$oUIElement=_UIA_getObjectByFindAll("Showdetails.mainwindow", "title:=Show details;ControlType:=UIA_HyperlinkControlTypeId", $treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Show details;ControlType:=UIA_HyperlinkControlTypeId", $treescope_subtree)
_UIA_action($oUIElement,"click")
*** Detailed properties of the highlighted element ***
UIA_title:= <Show details>
UIA_iaccessiblevalue:= <Show details>
UIA_iaccessiblechildId:= <0>
UIA_BoundingRectangle:= <218;290;76;16>
 

Share this post


Link to post
Share on other sites
computergroove

This is a stand alone script that I have modified to give X,Y,HexColor,DECColor

#include <GuiConstants.au3>
#include <date.au3>

Opt("GUIOnEventMode", 1)
Opt("WinTitleMatchMode", 4) ; set title matchmode to advanced

Global $xoffset = 37
Global $yoffset = 23
Global $wposx, $wposy, $DT, $cWIN, $xcalcL, $xcalcR, $ycalc, $cpos, $pos, $tpos, $hexV, $pcolor
Global $title = "Your Title Here"

HotKeySet("{ESC}", "Terminate") ; a way out of this
;HotKeySet("!f", "_color"); check for color

$pGUI = GUICreate($title, 300, 13, -1, -1, $WS_POPUP);Make a GUI next to mouse
$startLAB = GUICtrlCreateLabel(" X: 0000, Y: 0000", 0, 0, 300, 13);Fill GUI with coords
GUICtrlSetBkColor($startLAB, 0xCCFFFF);Background color of GUI window

WinSetOnTop($pGUI, "", 1);Make GUI topmost

GUISetState(@SW_SHOW)

While 1
    ;_checkWIN()
    _nMGP()
WEnd

Func _nMGP()
    Local $_cpos = MouseGetPos()
    Sleep(0010)
    $pcolor = PixelGetColor($_cpos[0],$_cpos[1])
    $pos = MouseGetPos()
    GUICtrlSetData($startLAB, ' X: ' & $pos[0] & ', Y: ' & $pos[1] & ' HEX: ' & HEX($pcolor,6) & ' DEC: ' & $pcolor)
    If $DT = 1 Then
        $xcalcR = .95 * @DesktopWidth
        $xcalcL = .05 * @DesktopWidth
        $ycalc = .90 * @DesktopHeight
        If $pos[1] > $ycalc Then
            $wposy = $pos[1] - $yoffset * 2 ; If too close to bottom of screen position above mouse pointer
        Else
            $wposy = $pos[1] + $yoffset ; Position label beneath the mouse pointer
        EndIf
        If $pos[0] > $xcalcR Then ; If too close to right side of screen move it
            $wposx = $pos[0] - $xoffset * 3
        ElseIf $pos[0] < $xcalcL Then ; If too close to left side of screen move it
            $wposx = $pos[0] + 10
        Else
            $wposx = $pos[0] - $xoffset ; Use normal offsets for positioning label
        EndIf
    Else
        _clientmouse()
    EndIf
    WinMove($title, "", $wposx, $wposy) ; Move the label appropriate to follow the mouse
EndFunc   ;==>_nMGP

;Func _checkWIN()
;    $cWIN = WinGetTitle("[ACTIVE]")
;    If $cWIN <> $title Then
;        TrayTip("", $cWIN, 30)
;        Opt("MouseCoordMode", 0)
;        $DT = 0
;    Else
;        TrayTip("", "DESKTOP", 30)
;        Opt("MouseCoordMode", 1)
;        $DT = 1
;    EndIf
;EndFunc   ;==>_checkWIN

Func _clientmouse()
    Opt("MouseCoordMode", 1)
    $tpos = MouseGetPos()
    $cpos = WinGetPos($cWIN)
    $xcalcR = .95 * $cpos[2]
    $xcalcL = .05 * $cpos[2]
    $ycalc = .90 * $cpos[3]
    If $tpos[1] > $ycalc Then
        $wposy = $tpos[1] - $yoffset * 2 ; If too close to bottom of screen position above mouse pointer
    Else
        $wposy = $tpos[1] + $yoffset ; Position label beneath the mouse pointer
    EndIf
    If $tpos[0] > $xcalcR Then ; If too close to right side of screen move it
        $wposx = $tpos[0] - $xoffset * 3
    ElseIf $tpos[0] < $xcalcL Then ; If too close to left side of screen move it
        $wposx = $tpos[0] + 10
    Else
        $wposx = $tpos[0] - $xoffset ; Use normal offsets for positioning label
    EndIf
EndFunc   ;==>_clientmouse

;Func _color()
;    Local $_cpos = MouseGetPos()
;    Local $pcolor
    ; - ;$pcolor = PixelGetColor($_cpos[0],$_cpos[1])
;    $hexV = "0x" & Hex($pcolor,6)
;    Local $fOpen = FileOpen(@ScriptDir & "\color.txt",1)
;    FileWrite($fOpen,@CRLF & _NowDate() & " " & _NowTime() & " : " & "X: " & $_cpos[0] & _
;        "," & "Y: " & $_cpos[1] & " | " & "Color: " & $hexV)
;    FileClose($fOpen)
;EndFunc

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Keep this. It has helped me countless times in getting x and y positions

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • Rammanan
      By Rammanan
      Hi all, Below is my script,
      Pls advise me if any wrong on that....File exit in location but the return -1.
      FileOpen($file, 0)
         $line = FileReadLine($file)
         MsgBox(0,'',$line)
      FileClose($file)
      Local $aArray = _FileListToArrayRec($serverpath, "*|*.txt", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_NOPATH)
      If @error Then
              MsgBox($MB_SYSTEMMODAL, "Ooops!", "No files found")
          Else
          ;_ArrayDisplay($aArray, "Sorted tree")
                 Local $hSearch = FileFindFirstFile($line)
               MsgBox(0,'',$hSearch)
       
    • JNutt
      By JNutt
      I'm trying ot use controlClick to click on button. So I'm using the Window Info Finder tool. But I noticed that the control ID in windowInfo changes each time I restart the app.  
      Am I doing this wrong.
    • Theodoor
      By Theodoor
      Hi,
      I am trying to use the ControlClick in a "save as"-window to select the path of where to save the document.
      I found out that when in press the icon in front of the path, i select the path. So I am trying to press that button (i have attached a print screen of this window).
      While trying to figure out how i had to use the ControlClick, it said somewhere that i could us Au3Info to find out what title,... i should use with the ControlClick.
      The result of the Au3Info I have attached aswel.
      The ControlClick that i tried are these: (and none of these even move the mouse)
      ControlClick("[CLASS:ToolbarWindow32; INSTANCE:4]", "", "", "Left" ,1 ,10,10)
      ControlClick("[CLASS:ToolbarWindow32; INSTANCE:4]", "", "1001", "Left" ,1 ,10,10)
      ControlClick("[CLASS:ToolbarWindow32]", "", "", "Left" ,1 ,10,10)
      ControlClick("Save project as", "", "", "Left" ,1 ,10,10)
      I don't know what I am doing wrong.
      Should I use a controlID? is my windowtitle wrong?
      Can anyone help me?
      Thanks in advance,
      Theo


    • Trisha
      By Trisha
      I tried (using AutoIt) to automate a scenario where i  have to open IE with specific URL on my extranet(Xen Desktop or Citrix ) ,from there i need to download  file and then through WinSCP; I  have to move that file to another location that can be access from my Local system using VMWare.
      I did as far as the above step. Now i want to navigate from my extranet to my local desktop system. But i am not able to move  from there.Mouse click is also not working.Please find the below screenshot highlighted in YELLOW.
       


    • CYCho
      By CYCho
      Browsers seem to have a built-in feature to insert a check box (Prevent this page from creating additional dialogues) into the message box created by an web site. This check box seems to appear when the same message box is triggered in succession within a short span of time. My problem is that AutoIt cannot read the text of the IE11 message box when this check box is included. I started to experence this after my Windows 10 was updated to Anniversay Update. I would like to know if anyone has experienced the same thing and if there is a solution to let the AutoIt read the text.
×