Jump to content
Sign in to follow this  
CyberSlug

Gui Coordinate Conversion

Recommended Posts

CyberSlug

(Thanks to Larry and Valik for helping me figure this out)

In AutoIt-Gui, the coordinates of controls are relative to the window client area. If you want to compare the position of the mouse to the position of a control, then the following functions will help you:

_mouseClientPos()

similar to mouseGetPos() but result is in terms of GUI coordinates

_mouseClientMove($x, $y, $speed)

similar to mouseMove(...) but the parameters are GUI coordinates

Global $title = '' ;empty string means active window

HotKeySet("{Esc}", "MouseMoveToZeroZero")
  Func MouseMoveToZeroZero()
    _mouseClientMove(0,0, 0)
  EndFunc

While 1
  sleep(100)
  $p = _mouseClientPos()
  ToolTip($p[0] & ',' & $p[1])
WEnd
Exit


; Convert window mouse coordinates to window client coords
Func _mouseClientPos()
  $mouseCoordModeBAK = Opt("MouseCoordMode", 0);relative to window

  Local $tmp[2]
  Local $windowSize = WinGetPos($title)
  Local $clientSize = WinGetClientSize($title)
    If @error Then Return $tmp;in case the taskbar is active
  Local $mouseCoord = MouseGetPos()
  Local $border = ($windowSize[2] - $ClientSize[0]) / 2

  $tmp[0] = $mouseCoord[0] - $windowSize[2] + $clientSize[0] + $border
  $tmp[1] = $mouseCoord[1] - $windowSize[3] + $clientSize[1] + $border

  Opt("MouseCoordMode", $mouseCoordModeBAK);original
  Return $tmp
EndFunc


; Convert client mouse coords to window mouse coords
Func _mouseClientMove($x, $y, $speed)
  $mouseCoordModeBAK = Opt("MouseCoordMode", 0);relative to window

  Local $windowSize = WinGetPos($title)
  Local $clientSize = WinGetClientSize($title)
    If @error Then Return;in case the taskbar is active
  Local $mouseCoord = MouseGetPos()
  Local $border = ($windowSize[2] - $ClientSize[0]) / 2

  $left = $x + $windowSize[2] - $clientSize[0] - $border
  $top  = $y + $windowSize[3] - $clientSize[1] - $border

  MouseMove($left, $top, $speed)

  Opt("MouseCoordMode", $mouseCoordModeBAK);original
EndFunc

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites
icadea

thanks

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  

×