I wanted to have the best of both worlds, so I came up with this script. It's a good amount of borrowed code from "corrupt", a user here on the AHK forums. I've modified the code a little so that it doesn't go all the way to the top of the window (bar and all), and doesn't go to the very edges of any side of the screen. Also, it's now activated with CapsLock.
; ; Author: Bkid <[email protected]> ; Thanks to corrupt for the original mouse locking code. ; ; This script finds the size of the SC2 window, its edges, and locks ; the mouse into the window. This way, you can use the mouse scroll, ; even if you're windowed. You can lock the mouse by turning CapsLock on, ; and unlock it by turning CapsLock off. #SingleInstance Force #Persistent Menu, Tray, NoStandard Menu, Tray, Add, Credits Menu, Tray, Add, Exit TrayTip, Mouse lock v1.0 for SC2, CapsLock on = Lock the mouse to the StarCraft 2 window.`nCapsLock off = Release the mouse., 5, 1 SetCapsLockState, Off SetTimer, LockCheck, 5 LockCheck: GetKeyState, CapsState, CapsLock, T If CapsState = D { Lock("StarCraft II") Suspend, Off WinActivate, StarCraft II Return } else { 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 } Credits: MsgBox, 262144,, Mouse lock v1.0 for StarCraft II by Bkid ([email protected]).`n`nThanks to corrupt on the AutoHotKey forums for the`ninitial mouse locking code. return Exit: exitapp
What needs to be added/changed:
* A better way to activate the window (right now it can be screwed up if you have a folder open named "StarCraft II"
* Bug fixes/things I haven't realized are wrong yet.
* Code clean up