Sign in to follow this  
Followers 0

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

8 posts in this topic

Please help! 
I am using Autoit version 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.
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

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

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

#4 ·  Posted (edited)

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


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                                                          Forum Rules
Live for the present,
Dream of the future,
Learn from the past.

Share this post

Link to post
Share on other sites

#5 ·  Posted (edited)

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)



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?



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

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) 
6: Title is: <Diagnostic Report> Class   := <> controltype:= <UIA_WindowControlTypeId> ,<50032> , (0000C370) 
"Title:=Diagnostic Report;controltype:=UIA_WindowControlTypeId;" 
5: Title is: <> Class   := <> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 
4: Title is: <> Class   := <> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 
3: Title is: <> Class   := <> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 
2: Title is: <> Class   := <> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 
1: Title is: <Status> Class   := <> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 
0: Title is: <Show details> Class   := <> controltype:= <UIA_TextControlTypeId> ,<50020> , (0000C364) 
"Title:=Show details;controltype:=UIA_TextControlTypeId;" 
*** Standard code ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP6=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Diagnostic Report;controltype:=UIA_WindowControlTypeId;", $treescope_children) 
Local $oP5=_UIA_getObjectByFindAll($oP6, "Title:=;controltype:=UIA_PaneControlTypeId;", $treescope_children) 
Local $oP4=_UIA_getObjectByFindAll($oP5, "Title:=;controltype:=UIA_PaneControlTypeId;", $treescope_children) 
Local $oP3=_UIA_getObjectByFindAll($oP4, "Title:=;controltype:=UIA_PaneControlTypeId;", $treescope_children) 
Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_PaneControlTypeId;", $treescope_children) 
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=Status;controltype:=UIA_PaneControlTypeId;", $treescope_children) 
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Show details;controltype:=UIA_TextControlTypeId;", $treescope_children) 
;~ 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)
*** Detailed properties of the highlighted element ***
UIA_title:= <Show details>
UIA_iaccessiblevalue:= <Show details>
UIA_iaccessiblechildId:= <0>
UIA_BoundingRectangle:= <218;290;76;16>
UIA_ProcessId:= <6756>
UIA_ControlType:= <50005>
UIA_LocalizedControlType:= <hyperlink>
UIA_Name:= <Show details>
UIA_HasKeyboardFocus:= <False>
UIA_IsKeyboardFocusable:= <True>
UIA_IsEnabled:= <True>
UIA_Culture:= <0>
UIA_IsControlElement:= <True>
UIA_IsContentElement:= <True>
UIA_IsPassword:= <False>
UIA_NativeWindowHandle:= <0>
UIA_IsOffscreen:= <False>
UIA_Orientation:= <0>
UIA_IsRequiredForForm:= <False>
UIA_IsDockPatternAvailable:= <False>
UIA_IsExpandCollapsePatternAvailable:= <False>
UIA_IsGridItemPatternAvailable:= <False>
UIA_IsGridPatternAvailable:= <False>
UIA_IsInvokePatternAvailable:= <True>
UIA_IsMultipleViewPatternAvailable:= <False>
UIA_IsRangeValuePatternAvailable:= <False>
UIA_IsScrollPatternAvailable:= <False>
UIA_IsScrollItemPatternAvailable:= <False>
UIA_IsSelectionItemPatternAvailable:= <False>
UIA_IsSelectionPatternAvailable:= <False>
UIA_IsTablePatternAvailable:= <False>
UIA_IsTableItemPatternAvailable:= <False>
UIA_IsTextPatternAvailable:= <False>
UIA_IsTogglePatternAvailable:= <False>
UIA_IsTransformPatternAvailable:= <False>
UIA_IsValuePatternAvailable:= <True>
UIA_IsWindowPatternAvailable:= <False>
UIA_ValueValue:= <Show details>
UIA_ValueIsReadOnly:= <False>
UIA_RangeValueValue:= <0>
UIA_RangeValueIsReadOnly:= <True>
UIA_RangeValueMinimum:= <0>
UIA_RangeValueMaximum:= <0>
UIA_RangeValueLargeChange:= <0>
UIA_RangeValueSmallChange:= <0>
UIA_ScrollHorizontalScrollPercent:= <0>
UIA_ScrollHorizontalViewSize:= <100>
UIA_ScrollVerticalScrollPercent:= <0>
UIA_ScrollVerticalViewSize:= <100>
UIA_ScrollHorizontallyScrollable:= <False>
UIA_ScrollVerticallyScrollable:= <False>
UIA_SelectionCanSelectMultiple:= <False>
UIA_SelectionIsSelectionRequired:= <False>
UIA_GridRowCount:= <0>
UIA_GridColumnCount:= <0>
UIA_GridItemRow:= <0>
UIA_GridItemColumn:= <0>
UIA_GridItemRowSpan:= <1>
UIA_GridItemColumnSpan:= <1>
UIA_DockDockPosition:= <5>
UIA_ExpandCollapseExpandCollapseState:= <3>
UIA_MultipleViewCurrentView:= <0>
UIA_WindowCanMaximize:= <False>
UIA_WindowCanMinimize:= <False>
UIA_WindowWindowVisualState:= <0>
UIA_WindowWindowInteractionState:= <0>
UIA_WindowIsModal:= <False>
UIA_WindowIsTopmost:= <False>
UIA_SelectionItemIsSelected:= <False>
UIA_TableRowOrColumnMajor:= <2>
UIA_ToggleToggleState:= <2>
UIA_TransformCanMove:= <False>
UIA_TransformCanResize:= <False>
UIA_TransformCanRotate:= <False>
UIA_IsLegacyIAccessiblePatternAvailable:= <True>
UIA_LegacyIAccessibleChildId:= <0>
UIA_LegacyIAccessibleName:= <Show details>
UIA_LegacyIAccessibleValue:= <Show details>
UIA_LegacyIAccessibleRole:= <30>
UIA_LegacyIAccessibleState:= <1048576>
UIA_LegacyIAccessibleDefaultAction:= <Click>
UIA_IsDataValidForForm:= <False>
UIA_ProviderDescription:= <[pid:6756,hwnd:0x0 Main(parent link):Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]>
UIA_IsItemContainerPatternAvailable:= <False>
UIA_IsVirtualizedItemPatternAvailable:= <False>
UIA_IsSynchronizedInputPatternAvailable:= <False>

Share this post

Link to post
Share on other sites

#8 ·  Posted (edited)

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


While 1

Func _nMGP()
    Local $_cpos = MouseGetPos()
    $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
            $wposy = $pos[1] + $yoffset ; Position label beneath the mouse pointer
        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
            $wposx = $pos[0] - $xoffset ; Use normal offsets for positioning label
    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
        $wposy = $tpos[1] + $yoffset ; Position label beneath the mouse pointer
    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
        $wposx = $tpos[0] - $xoffset ; Use normal offsets for positioning label
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)

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

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  
Followers 0

  • Similar Content

    • breakbadsp
      By breakbadsp
      AutoIT AU3info doeas not detect all gui objects uniquely for .NET GUIs developed in C#.
      this is not working now i am using COM windows approach for this, But its very difficult.
      Please let me know if anyone has done it before.
    • KB505
      By KB505
      I'm starting a script in AutoIT to automize a task in a software. I need to click a several Controls. 
      I'm just starting to learn AutoIT, and discovered that we can use the Window Info tool (au3info) to identify controls precisely and targetting safely a specific button.
      However, when I try it, I realize that most of the controls in my toolbar have the same Control Info (No ID, same class, same instance, ...). The only thing that changes is the ControlClicks Coord but I don't think that it's interesting, I don't see the difference with the Mouse Coordinates. Besides, I was aiming to write a stable script that would work even if the button changes a little bit of place for example. 
      Should I use another tool that Window Info tool to detect this Controls ? Is there another way to identify a Control ? 
      Thank you in advance for your help
    • SorryButImaNewbie
      By SorryButImaNewbie
      I'm developing again (everybody ruuun! )
      I would like to develope a script that goes through basicly every user control on a window, and log things that happens, and maybe do some screenshots. I did something like this before.
      My problem, which I would like to avoid this time (to improve my understanding and skill) , was that when I was unable to get a ControlID or handler or anything, I simply did some math and clicked on the coordinates it should have been (for example, maxing the window, and knowing the initial set up I was ablo to calculate given control position). I know that this is a bad solution for a number of reasons. 
      Now I got authorization to install autoIT here, and i started to the work, AU3Info was unable to find anything on the window (this could be a problem, since autoIT doesn't see anything on it then, if I understood the help file) So I got the SimpleSpy script (source:
      I added a bit of code to the original to display ID as well, what I received is this:
      Mouse position is retrieved 115-207
      At least we have an element title: [ADD] class: [Button] ID: [50000] (<-- coded this to display ID here as well)
      Having the following values for all properties: 
      Title is: <ADD>    Class   := <Button>    controltype:= <UIA_ButtonControlTypeId>    ,<50000>    , (0000C350)    10;187;120;35
      *** Parent Information top down ***
      3: Title is: <Compass>    Class   := <Window>    controltype:= <UIA_WindowControlTypeId>    ,<50032>    , (0000C370)    -8;-8;1936;1056
      2: Title is: <>    Class   := <MainView>    controltype:= <UIA_CustomControlTypeId>    ,<50025>    , (0000C369)    0;23;1920;1017
      1: Title is: <>    Class   := <TileNavigationView>    controltype:= <UIA_CustomControlTypeId>    ,<50025>    , (0000C369)    0;23;1920;967
      0: Title is: <>    Class   := <AreasView>    controltype:= <UIA_CustomControlTypeId>    ,<50025>    , (0000C369)    0;132;1920;858
      so far I wrote this script:
      WinActivate('Test') ;It works!! :D first official interaction Sleep(1000) ;1 sec sleep to be sure ControlClick('Test', '', '50000') If @error Then MsgBox($MB_SYSTEMMODAL, 'Error', 'ControlClick error') EndIf Sleep(1000) MsgBox(1,"Tracer message", 'ControlClick has happened') ;MouseClick() ;ControlCommand() AutoIt activates the window, but the click on the given button doesnt happen (I tried to write 50000 without ' ' on ID).
      M'I doing the @error part correctly ? (no error Msg has been displayed), sorry I rarely use AutoIT and seems to forget less and less after each neglect, but still I'm far from a proffessional
      Any help or suggestion is welcome, thank you for your time and insight!
    • brad3260
      By brad3260
      Hello everyone, I have been beating my head against the wall all day today over this and am hoping someone can help. I work for a company who makes assistive technology and I have multiple consumers who want to use the Mail app included in Windows 10. Most of these consumers are using eye tracking technology so the MouseClick is not an option since their eyes are constantly controlling the mouse cursor so it would be a battle between that function and their eyes. And hence I need to use ControlClick. I'm having problems with it though, I can't get it to click anything in the app. I've been left clicking on things with no apparent luck. However, when I changed it to right click, something very interesting happens, the window menu (the one you get when you hit ALT + SPACE) opens every time the ControlClick runs, regardless of the X,Y coordinates as if it is right clicking at the top left of the window every time.
      Based on the Window Info, the entire app is one big control whose position is 0,40 and the size is 1440,838.
      Does anybody have any ideas why I can apparently only click on the top left corner of the app? Any direction is greatly appreciated!
      Opt('MouseClickDownDelay', 100) Opt('WinTitleMatchMode', 2) Local $hWnd = WinActivate('Gmail') $inc = 30 For $hi = 1 To 10 Step 1 $hadj = $hi * $inc For $i = 1 To 10 Step 1 $adj = $i * $inc $j = ControlClick($hWnd, "", "[CLASS:ApplicationFrameInputSinkWindow; INSTANCE:1]", "Right", 1, $hadj, $adj) MouseMove($hadj, $adj, 3) Next Next  
    • Akashrai
      By Akashrai
      I want to automate a client application but auto it info tool is not detecting the GUI components. I don't know what to do. please help me out. Screenshot  of first login page of application is in attachment