Skip to content

Instantly share code, notes, and snippets.

@honboubao
Created May 24, 2026 13:31
Show Gist options
  • Select an option

  • Save honboubao/db2d26a71193c595da9835e45ff9bbd4 to your computer and use it in GitHub Desktop.

Select an option

Save honboubao/db2d26a71193c595da9835e45ff9bbd4 to your computer and use it in GitHub Desktop.
AutoHotKey v2 script to activate mod keys and enable fast scrolling when mouse buttons are being held for more than 300ms.
; Hold time threshold in seconds (0.3 = 300 ms)
HoldTime := 0.3
; Multiplier for faster scrolling
ScrollSpeed := 10
; Timers start disabled
SetTimer(CheckHoldCtrl, 0)
SetTimer(CheckHoldShift, 0)
SetTimer(CheckHoldAlt, 0)
; --------------------------------------------------
; Back button (XButton1) -> Shift key
; --------------------------------------------------
XButton1::
{
global HoldTime
if KeyWait("XButton1", "T" HoldTime) {
; Quick press
Send("{XButton1}")
} else {
; Held
Send("{Shift Down}")
SetTimer(CheckHoldShift, 10)
}
}
CheckHoldShift()
{
if !GetKeyState("XButton1", "P") {
if GetKeyState("Shift", "P") {
Send("{Shift Up}")
}
SetTimer(CheckHoldShift, 0)
}
}
; --------------------------------------------------
; Forward button (XButton2) -> Ctrl key
; --------------------------------------------------
XButton2::
{
global HoldTime
if KeyWait("XButton2", "T" HoldTime) {
; Quick press
Send("{XButton2}")
} else {
; Held
Send("{Ctrl Down}")
SetTimer(CheckHoldCtrl, 10)
}
}
CheckHoldCtrl()
{
if !GetKeyState("XButton2", "P") {
if GetKeyState("Ctrl", "P") {
Send("{Ctrl Up}")
}
SetTimer(CheckHoldCtrl, 0)
}
}
; --------------------------------------------------
; Middle mouse button (MButton) -> Alt key
; --------------------------------------------------
MButton::
{
global HoldTime
if KeyWait("MButton", "T" HoldTime) {
; Quick press
Send("{MButton}")
} else {
; Held
Send("{Alt Down}")
SetTimer(CheckHoldAlt, 10)
}
}
CheckHoldAlt()
{
if !GetKeyState("MButton", "P") {
if GetKeyState("Alt", "P") {
Send("{Alt Up}")
}
SetTimer(CheckHoldAlt, 0)
}
}
; --------------------------------------------------
; Faster scrolling when both side buttons are held
; --------------------------------------------------
*WheelUp::
{
global ScrollSpeed
if GetKeyState("XButton1", "P") && GetKeyState("XButton2", "P") {
if GetKeyState("Ctrl", "P") {
Send("{Ctrl Up}")
}
if GetKeyState("Shift", "P") {
Send("{Shift Up}")
}
Send("{WheelUp " ScrollSpeed "}")
} else {
Send("{WheelUp}")
}
}
*WheelDown::
{
global ScrollSpeed
if GetKeyState("XButton1", "P") && GetKeyState("XButton2", "P") {
if GetKeyState("Ctrl", "P") {
Send("{Ctrl Up}")
}
if GetKeyState("Shift", "P") {
Send("{Shift Up}")
}
Send("{WheelDown " ScrollSpeed "}")
} else {
Send("{WheelDown}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment