Lock mouse movement to only allow horizontal movement (vertical too if you want) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
teadrinker
Posts: 4336
Joined: 29 Mar 2015, 09:41
Contact:

Re: Lock mouse movement to only allow horizontal movement (vertical too if you want)

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)
    }
}
User avatar
busymind
Posts: 5
Joined: 12 Apr 2024, 01:32

Re: Lock mouse movement to only allow horizontal movement (vertical too if you want)

13 Apr 2024, 18:38

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.
User avatar
busymind
Posts: 5
Joined: 12 Apr 2024, 01:32

Re: Lock mouse movement to only allow horizontal movement (vertical too if you want)

14 Apr 2024, 15:17

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.
Attachments
MouseLock.gif
(193.16 KiB) Downloaded 85 times
teadrinker
Posts: 4336
Joined: 29 Mar 2015, 09:41
Contact:

Re: Lock mouse movement to only allow horizontal movement (vertical too if you want)

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)
    }
}
User avatar
busymind
Posts: 5
Joined: 12 Apr 2024, 01:32

Re: Lock mouse movement to only allow horizontal movement (vertical too if you want)  Topic is solved

14 Apr 2024, 16:43

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.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: FalseShepard, GEOVAN and 350 guests