Jump to content

_MouseTrap() and MouseCoordMode


mcvetyty
 Share

Recommended Posts

Can anyone assist me with this?

I cannot seem to get _MouseTrap() to work with Client coordinates instead of absolute window coordinates?

My code is simple, i basically am trying this:

AutoItSetOption("MouseCoordMode", 2)
_MouseTrap(80, 70)

Except that seems to do coordinates 80,70 of the Screen, and not the client program... Is there a way to have MouseTrap use the client window coordinates?

Thanks!

Link to comment
Share on other sites

  • Moderators

The _MouseTrap() example in the help file does exactly that, traps in the client area of the GUI created using WinGetPos().

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Guess you could always just mod a UDF around _MouseTrap() itself to make life easier (Not tested but once)

HotKeySet('{ESC}', '_ExitNow')

Dim $GUI, $coords[4], $msg

$GUI = GUICreate("Mouse Trap Example", 392, 323)

GUISetState()

While 1
    _MouseTrapClient($GUI, 80, 70)
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            ;;;
    EndSelect
WEnd
_MouseTrap ()
Exit

Func _MouseTrapClient($hWnd = '', $nXTopLeft = 0, $nYTopLeft = 0, $nXBottomRight = 0, $nYBottomRight = 0)
    If $hWnd = '' And $nXTopLeft = 0 And $nYTopLeft = 0 And $nXBottomRight = 0 And $nYBottomRight = 0 Then Return _MouseTrap()
    If Not IsHWnd($hWnd) And WinExists($hWnd) Then $hWnd = HWnd($hWnd)
    Local $aWPos = WinGetPos($hWnd)
    If IsArray($aWPos) Then
        If $nXBottomRight = 0 Then $nXBottomRight = $nXTopLeft
        If $nYBottomRight = 0 Then $nYBottomRight = $nYTopLeft
        Return _MouseTrap($aWPos[0] + $nXTopLeft, $aWPos[1] + $nYTopLeft, $aWPos[0] + $nXBottomRight, $aWPos[1] + $nYBottomRight)
    EndIf
    Return SetError(1, 0, '')
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • 1 year later...
  • Moderators

Or you could use the following function after moving the mouse to the position to be locked

Cheers

Wakido

Func MouseTrapCurrent()
        Opt("MouseCoordMode",0)
        $local = MouseGetPos()
        _MouseTrap($local[0],$local[1])
        Opt("MouseCoordMode",2)
EndFunc
You're serious? You revived a 20 month old thread for this. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You're serious? You revived a 20 month old thread for this.

I posted a solution as the ones previously posted didn't work with Opt("MouseCoordMode",2)

And for the sake of anyone who is using the Forums search functions for answers before re-posting questions, I thought it may be appropriate there was a working solution in this thread.

I apologise if this is offensive.

wakido

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