Page 2 of 2
Re: Lock mouse movement to only allow horizontal movement (vertical too if you want)
Posted: 13 Apr 2024, 16:32
by teadrinker
Fixed:
Code: Select all
#Requires AutoHotkey v1
~LShift::
~LCtrl::
ToolTip mouse movement restricted.
ClipCursor(A_ThisHotkey)
KeyWait, % SubStr(A_ThisHotkey, 2)
ClipCursor()
ToolTip
Return
ClipCursor(hk := "") {
if !hk
DllCall("ClipCursor", "Ptr", 0)
else {
CoordMode, Mouse
MouseGetPos, X, Y
VarSetCapacity(RECT, 16, 0)
if InStr(hk, "Shift")
NumPut(-0xFFFF, RECT, "Int"), NumPut(Y, RECT, 4), NumPut(0xFFFF, RECT, 8), NumPut(Y + 1, RECT, 12, "Int")
else
NumPut(X, RECT), NumPut(X + 1, RECT, 8), NumPut(A_ScreenHeight, RECT, 12, "Int")
DllCall("ClipCursor", "Ptr", &RECT)
}
}
Re: Lock mouse movement to only allow horizontal movement (vertical too if you want)
Posted: 13 Apr 2024, 18:38
by busymind
teadrinker wrote: ↑13 Apr 2024, 16:32
Fixed:
Code: Select all
#Requires AutoHotkey v1
~LShift::
~LCtrl::
ToolTip mouse movement restricted.
ClipCursor(A_ThisHotkey)
KeyWait, % SubStr(A_ThisHotkey, 2)
ClipCursor()
ToolTip
Return
ClipCursor(hk := "") {
if !hk
DllCall("ClipCursor", "Ptr", 0)
else {
CoordMode, Mouse
MouseGetPos, X, Y
VarSetCapacity(RECT, 16, 0)
if InStr(hk, "Shift")
NumPut(-0xFFFF, RECT, "Int"), NumPut(Y, RECT, 4), NumPut(0xFFFF, RECT, 8), NumPut(Y + 1, RECT, 12, "Int")
else
NumPut(X, RECT), NumPut(X + 1, RECT, 8), NumPut(A_ScreenHeight, RECT, 12, "Int")
DllCall("ClipCursor", "Ptr", &RECT)
}
}
Thank you so much, works perfectly.
Re: Lock mouse movement to only allow horizontal movement (vertical too if you want)
Posted: 14 Apr 2024, 15:17
by busymind
teadrinker wrote: ↑13 Apr 2024, 16:32
Fixed:
Code: Select all
#Requires AutoHotkey v1
~LShift::
~LCtrl::
ToolTip mouse movement restricted.
ClipCursor(A_ThisHotkey)
KeyWait, % SubStr(A_ThisHotkey, 2)
ClipCursor()
ToolTip
Return
ClipCursor(hk := "") {
if !hk
DllCall("ClipCursor", "Ptr", 0)
else {
CoordMode, Mouse
MouseGetPos, X, Y
VarSetCapacity(RECT, 16, 0)
if InStr(hk, "Shift")
NumPut(-0xFFFF, RECT, "Int"), NumPut(Y, RECT, 4), NumPut(0xFFFF, RECT, 8), NumPut(Y + 1, RECT, 12, "Int")
else
NumPut(X, RECT), NumPut(X + 1, RECT, 8), NumPut(A_ScreenHeight, RECT, 12, "Int")
DllCall("ClipCursor", "Ptr", &RECT)
}
}
It works so much better than the previous script, but I noticed that it doesn't lock the cursor instantly, and sometimes causes the mouse to be free for a few moments before locking it, even though I'm holding down the button already, can you make it to lock instantly? it's not a huge problem, but sometimes it causes a bit of a curve at the first part of the highlights or lines especially when I'm highlighting things a bit fast and mostly when my mouse has been moving in a vertical axis before locking on horizontal axis.
It's not that important but if you had the time to fix it, it'll be even better. Thanks.
Re: Lock mouse movement to only allow horizontal movement (vertical too if you want)
Posted: 14 Apr 2024, 16:27
by teadrinker
Try this:
Code: Select all
#Requires AutoHotkey v1
~LShift::
~LCtrl::
BlockInput, MouseMove
ToolTip mouse movement restricted.
ClipCursor(A_ThisHotkey)
BlockInput, MouseMoveOff
KeyWait, % SubStr(A_ThisHotkey, 2)
ClipCursor()
ToolTip
Return
ClipCursor(hk := "") {
if !hk
DllCall("ClipCursor", "Ptr", 0)
else {
CoordMode, Mouse
MouseGetPos, X, Y
VarSetCapacity(RECT, 16, 0)
if InStr(hk, "Shift")
NumPut(-0xFFFF, RECT, "Int"), NumPut(Y, RECT, 4), NumPut(0xFFFF, RECT, 8), NumPut(Y + 1, RECT, 12, "Int")
else
NumPut(X, RECT), NumPut(X + 1, RECT, 8), NumPut(A_ScreenHeight, RECT, 12, "Int")
DllCall("ClipCursor", "Ptr", &RECT)
}
}
Re: Lock mouse movement to only allow horizontal movement (vertical too if you want)
Posted: 14 Apr 2024, 16:43
by busymind
teadrinker wrote: ↑14 Apr 2024, 16:27
Try this:
Code: Select all
#Requires AutoHotkey v1
~LShift::
~LCtrl::
BlockInput, MouseMove
ToolTip mouse movement restricted.
ClipCursor(A_ThisHotkey)
BlockInput, MouseMoveOff
KeyWait, % SubStr(A_ThisHotkey, 2)
ClipCursor()
ToolTip
Return
ClipCursor(hk := "") {
if !hk
DllCall("ClipCursor", "Ptr", 0)
else {
CoordMode, Mouse
MouseGetPos, X, Y
VarSetCapacity(RECT, 16, 0)
if InStr(hk, "Shift")
NumPut(-0xFFFF, RECT, "Int"), NumPut(Y, RECT, 4), NumPut(0xFFFF, RECT, 8), NumPut(Y + 1, RECT, 12, "Int")
else
NumPut(X, RECT), NumPut(X + 1, RECT, 8), NumPut(A_ScreenHeight, RECT, 12, "Int")
DllCall("ClipCursor", "Ptr", &RECT)
}
}
Yep, fixed, you're literally the AHK wizard. THANK YOU.
Re: Lock mouse movement to only allow horizontal movement (vertical too if you want)
Posted: 14 Apr 2024, 16:53
by teadrinker
Glad to help!