Jump to content

MouseTrap


Recommended Posts

I'm attempting to use this code (compiled using the beta):

Func MouseTrap($l_left, $l_top, $l_right, $l_bottom)
   $v_Rect = DllStructCreate('int;int;int;int')
   DllStructSetData($v_Rect, 1, $l_left)
   DllStructSetData($v_Rect, 2, $l_top)
   DllStructSetData($v_Rect, 3, $l_right)
   DllStructSetData($v_Rect, 4, $l_bottom)
   $ai_Ret = DllCall('user32.dll', 'int', 'ClipCursor', 'ptr', DllStructGetPtr($v_Rect))
   DllStructDelete($v_Rect)
   Return $ai_Ret[0]
EndFunc

But I don't really understand it. I want to create a box around the cursor that only allows it to move one pixel to the right. (to combat my previous problem of the cursor being warped around against my control) Then, I want to unblock it again and allow free movement. I'm a little lost as to where to start...

Link to comment
Share on other sites

Do you know how to use the function with its parametres?

When running your computer normally you mouse is already 'trapped', it is confined by the width and height of your screen. Using the above function you can increase or decrease the width and height of the trap aswell as the starting co-ordinates.

The below will perform a screen mouse trap, as pointed above, you shold notice no difference because it just restrains your mouse to the screen width/height.

0,0 is the top left co-ordinate and @DesktopWidth, @DesktopHeight is the bottom right co-ordinate.

Hope you understand.

MouseTrap(0, 0, @DesktopWidth, @DesktopHeight)

While 1 
   Sleep(100)
Wend

Func MouseTrap($l_left, $l_top, $l_right, $l_bottom)
   $v_Rect = DllStructCreate('int;int;int;int')
   DllStructSetData($v_Rect, 1, $l_left)
   DllStructSetData($v_Rect, 2, $l_top)
   DllStructSetData($v_Rect, 3, $l_right)
   DllStructSetData($v_Rect, 4, $l_bottom)
   $ai_Ret = DllCall('user32.dll', 'int', 'ClipCursor', 'ptr', DllStructGetPtr($v_Rect))
   DllStructDelete($v_Rect)
   Return $ai_Ret[0]
EndFunc

qq

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