Created
April 9, 2016 09:27
-
-
Save tmplinshi/889a14874ac943a2fe8245338feaca37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
; Holding down left Control key to lock, release to unlock. | |
~LControl:: | |
LockCursorToPrimaryMonitor(true) | |
KeyWait, LControl | |
LockCursorToPrimaryMonitor(false) | |
return | |
*/ | |
LockCursorToPrimaryMonitor(lock = true) { | |
; Get mouse position on screen | |
VarSetCapacity( pt, 8, 0 ) | |
DllCall("GetCursorPos", "Ptr", &pt) | |
x := NumGet(pt, 0, "Int") | |
; If the cursor already on the second monitor, then leave it there. | |
if (x > A_ScreenWidth) { | |
return | |
} | |
; ClipCursor -- https://msdn.microsoft.com/en-us/library/windows/desktop/ms648383(v=vs.85).aspx | |
if (lock) { | |
VarSetCapacity(rect, 16, 0) | |
NumPut(A_ScreenWidth, rect, 8) | |
NumPut(A_ScreenHeight, rect, 12) | |
DllCall("ClipCursor", "ptr", &rect) | |
} else { | |
DllCall("ClipCursor", "ptr", 0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment