Jump to content

MouseTrap()


ezzetabi
 Share

Recommended Posts

A UDF...

AdlibEnable('_MouseTrapSet',50)
Sleep(20000)
AdlibDisable()



Exit
;Locks the mouse in the rectangle of size $iWidth x $iHeight with the upper left
;corner put in $iLeft, $iTop.
; Call this func via AblibEnable as in the example.

Func _MouseTrapSet()
   _MouseTrap(100, 100, 400, 400)
EndFunc

Func _MouseTrap($iLeft, $iTop, $iWidth, $iHeight)
   Local $aPos, $iRight, $iBottom

   $iRight = $iLeft + $iWidth
   $iBottom = $iTop + $iHeight
   
   If $iLeft < 0 Or $iTop < 0 Or $iRight > @DesktopWidth Or $iBottom > @DesktopHeight Then
      SetError (1)
      Return 0
   EndIf
   $aPos = MouseGetPos()
   
   Select
      Case $aPos[0] > $iRight
         MouseMove($iLeft, $aPos[1], 0)
      Case $aPos[0] < $iLeft
         MouseMove($iRight, $aPos[1], 0)
      Case $aPos[1] > $iBottom
         MouseMove($aPos[0], $iTop, 0)
      Case $aPos[1] < $iTop
         MouseMove($aPos[0], $iBottom, 0)
         
   EndSelect
   
EndFunc  ;==>_MouseTrap
Link to comment
Share on other sites

You could have some fun with this making a mouse wrap script:

_MouseTrap(2, 2, @DesktopWidth - 4, @DesktopHeight - 4)

When your cursor goes all the way to the left of the screen, it ends up at the right side. Same for all corners.

Who else would I be?
Link to comment
Share on other sites

  • 2 weeks later...

When I needed to make a mouse trap for windowed Warcraft 3 I found that the Windows.h "ClipCursor" function fit the situation like a glove. However it required a RECT structure as one of the parameters which AutoIt cannot provide (yet!). Hence I wrote two tiny C++ programs: one to trap the mouse and one to untrap it and an AutoIt script to interface with them. It wouldn't take much to simply pass an argument to one program that would do both but I was in a hurry. :)

If you are interested, the thread is here.

Edited by Christopher Blue
Link to comment
Share on other sites

  • 1 year later...

When I needed to make a mouse trap for windowed Warcraft 3 I found that the Windows.h "ClipCursor" function fit the situation like a glove. However it required a RECT structure as one of the parameters which AutoIt cannot provide (yet!). Hence I wrote two tiny C++ programs: one to trap the mouse and one to untrap it and an AutoIt script to interface with them. It wouldn't take much to simply pass an argument to one program that would do both but I was in a hurry. :)

If you are interested, the thread is here.

_MouseTrap in the beta include Misc.au3 uses the clipcursor

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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