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?

Lock mouse within specific window
Started by
haukur
, Mar 08 2011 07:47 PM
9 replies to this topic
#1
-
Posted 08 March 2011 - 07:47 PM

I don't quite understand, could you provide more details?
#2
-
Posted 08 March 2011 - 07:57 PM

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?
#3
-
Posted 08 March 2011 - 08:05 PM

search for ClipCursor
it will be something like this:
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" ) }
#4
-
Posted 08 March 2011 - 08:08 PM

Check out the ClipCursor function from SKAN here.
#5
-
Posted 08 March 2011 - 08:14 PM

thanks for the help guys but these scripts dont seem to work very well (the mouse jumps at the edges. I will keep trying.
#6
-
Posted 08 March 2011 - 09:30 PM

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.
EDIT:
<!-- m -->http://www.autohotke...pic.php?t=57243<!-- m -->
There we go. Check it out and be inspired.
#7
-
Posted 08 March 2011 - 09:42 PM

Please explain in detail what you mean? What does 'jump' mean ?thanks for the help guys but these scripts dont seem to work very well (the mouse jumps at the edges. I will keep trying.
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.
#8
-
Posted 08 March 2011 - 10:57 PM

thanks for the help guys, the link sumon posted works perfectly.
#9
-
Posted 08 March 2011 - 10:58 PM

I worked this out of the link sumon posted.
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?
#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?
#10
-
Posted 09 March 2011 - 02:54 AM
