Skip to content

Instantly share code, notes, and snippets.

@dijikul
Created September 7, 2026 15:53
Show Gist options
  • Select an option

  • Save dijikul/ae033872e5aadb1c30a2ff213d05c190 to your computer and use it in GitHub Desktop.

Select an option

Save dijikul/ae033872e5aadb1c30a2ff213d05c190 to your computer and use it in GitHub Desktop.
AutoHotkey Hold Left Click when Mouse4 Clicked
#Requires AutoHotkey v2.0
#Requires AutoHotkey v2.0
toggle := false
targetWindow := "" ; will store the window handle
XButton2:: {
global toggle, targetWindow
toggle := !toggle
if toggle {
targetWindow := WinActive("A") ; get the active window handle
Send("{LButton down}")
SetTimer MonitorConditions, 50 ; check conditions every 50ms
;ToolTip "Hold click: ON"
} else {
StopClicker()
}
}
MonitorConditions() {
global toggle, targetWindow
if !toggle
return
if !WinActive("ahk_id " targetWindow) || GetKeyState("LButton", "P") {
StopClicker()
}
}
StopClicker() {
global toggle
toggle := false
Send("{LButton up}")
SetTimer MonitorConditions, 0
;ToolTip "Hold click: OFF"
Sleep 100
ToolTip
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment