Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Lock mouse within specific window


  • Please log in to reply
9 replies to this topic
haukur
  • Members
  • 16 posts
  • Last active: Jun 18 2011 07:13 PM
  • Joined: 27 Feb 2011
So the thing is, I want to write a script that locks the mouse within a specific window, or a specific part of the screen if possible. Any ideas how I could go about to do this?

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
I don't quite understand, could you provide more details?

haukur
  • Members
  • 16 posts
  • Last active: Jun 18 2011 07:13 PM
  • Joined: 27 Feb 2011
It's for Warcraft III. I want to run it in windowed mode (maximized) but when I move the mouse to the sides of the screen it shows the "resize" mouse icon. I just want the mouse to stay within specific coordinates. Is this possible?

  • Guests
  • Last active:
  • Joined: --
search for ClipCursor
it will be something like this:
CoordMode, Mouse, Screen
^F2:: 
Confine := !Confine
ClipCursor( Confine, [color=red]0, 0, A_ScreenWidth, A_ScreenHeight[/color])
Return


ClipCursor( Confine=True, x1=0 , y1=0, x2=1, y2=1 ) 
{
VarSetCapacity(R,16,0),  NumPut(x1,&R+0),NumPut(y1,&R+4),NumPut(x2,&R+8),NumPut(y2,&R+12)
Return Confine ? DllCall( "ClipCursor", UInt,&R ) : DllCall( "ClipCursor" )
}



sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
Check out the ClipCursor function from SKAN here.

haukur
  • Members
  • 16 posts
  • Last active: Jun 18 2011 07:13 PM
  • Joined: 27 Feb 2011
thanks for the help guys but these scripts dont seem to work very well (the mouse jumps at the edges. I will keep trying.

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010
I saw a script for that (for Starcraft II) a while ago. Hold on, looking...

EDIT:

<!-- m -->http://www.autohotke...pic.php?t=57243<!-- m -->

There we go. Check it out and be inspired.

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009

thanks for the help guys but these scripts dont seem to work very well (the mouse jumps at the edges. I will keep trying.

Please explain in detail what you mean? What does 'jump' mean ?

I just tried the script posted by 'Guest' and it works to prevent the mouse from leaving the defined area.

The 4 parameters highlighted are the left, top, right and bottom coordinates of a limiting 'box'.
You may need to adjust them to limit the mouse where you want it.

haukur
  • Members
  • 16 posts
  • Last active: Jun 18 2011 07:13 PM
  • Joined: 27 Feb 2011
thanks for the help guys, the link sumon posted works perfectly.

haukur
  • Members
  • 16 posts
  • Last active: Jun 18 2011 07:13 PM
  • Joined: 27 Feb 2011
I worked this out of the link sumon posted.

#SingleInstance, force
#Persistent
Menu, Tray, Icon, WinEdgeOn.ico

Hotkey, ^!U, UnlockWarcraftIII

LockWarcraftIII:
Lock("Warcraft III")
Suspend, Off
WinActivate, ahk_class Warcraft III
return

UnlockWarcraftIII:
Lock()
Suspend, On
return

Lock(llwindowname="")
{
  VarSetCapacity(llrectA, 16)
  WinGetPos, llX, llY, llWidth, llHeight, %llwindowname%
  if (!llWidth and !llHeight) {
    DllCall("ClipCursor")
    return, false
  }
  Loop, 4 {
    DllCall("RtlFillMemory", UInt, &llrectA+0+A_Index-1, UInt, 1, UChar, (llX + 4) >> 8*A_Index-8)
    DllCall("RtlFillMemory", UInt, &llrectA+4+A_Index-1, UInt, 1, UChar, (llY + 30) >> 8*A_Index-8)
    DllCall("RtlFillMemory", UInt, &llrectA+8+A_Index-1, UInt, 1, UChar, (llWidth + llX - 4) >> 8*A_Index-8)
    DllCall("RtlFillMemory", UInt, &llrectA+12+A_Index-1, UInt, 1, UChar, (llHeight + llY - 4) >> 8*A_Index-8)
  }
  DllCall("ClipCursor", "UInt", &llrectA)
return, true
}

Exit:
ExitApp

I set ^!U to suspend the script, however, it doesn't seem to work. What could be the problem? What I'm trying to do is create a script that does this but also a hotkey to activate it and another to deactivate it. Is there any other way?