Skip to content

Instantly share code, notes, and snippets.

@ovcharik
Created December 4, 2019 20:29
Show Gist options
  • Save ovcharik/20af27323514fcf2b116f9cfaad420f4 to your computer and use it in GitHub Desktop.
Save ovcharik/20af27323514fcf2b116f9cfaad420f4 to your computer and use it in GitHub Desktop.
Autohotkey script. Throttle touchpad two finger scrolling in Windows Terminal.
; Config
#Persistent
#SingleInstance force
; 200 wheel events per second rate
#HotkeyInterval 1000
#MaxHotkeysPerInterval 200
DeactivateMenuItem := "Deactivate (Win + Shift + W)"
EnableHScrollMenuItem := "Enable HScroll (Win + Shift + H)"
ExitMenuItem := "Exit"
Menu, Tray, NoStandard
; Menu, Tray, Icon, wt-two-finger-scroll.ico
Menu, Tray, Add, %DeactivateMenuItem%, ToggleThrottle
Menu, Tray, Add, %EnableHScrollMenuItem%, ToggleHScroll
Menu, Tray, Add
Menu, Tray, Add, %ExitMenuItem%, Exit
; Variables
terminalTitle := "ahk_class CASCADIA_HOSTING_WINDOW_CLASS"
throttleTimeoutMs := 50
throttleActive := True
hScrollActive := False
isScollingUp := False
isScollingDown := False
isScollingLeft := False
isScollingRight := False
; Hotkeys
#If (throttleActive) && MouseIsOver(terminalTitle)
WheelUp::ScrollUp()
WheelDown::ScrollDown()
WheelLeft::ScrollLeft()
WheelRight::ScrollRight()
Return
#If WinActive(terminalTitle)
#z::Goto, ToggleThrottle
#+h::Goto, ToggleHScroll
Return
; Event handlers
ToggleThrottle:
throttleActive := !throttleActive
If (throttleActive)
Menu, Tray, Uncheck, %DeactivateMenuItem%
Else
Menu, Tray, Check, %DeactivateMenuItem%
Return
ToggleHScroll:
hScrollActive := !hScrollActive
If (hScrollActive)
Menu, Tray, Check, %EnableHScrollMenuItem%
Else
Menu, Tray, Uncheck, %EnableHScrollMenuItem%
Return
Exit:
ExitApp
UnlockScrollUp:
isScollingUp := False
Return
UnlockScrollDown:
isScollingDown := False
Return
UnlockScrollLeft:
isScollingLeft := False
Return
UnlockScrollRight:
isScollingRight := False
Return
; Functions
MouseIsOver(WinTitle) {
MouseGetPos,,, Win
Return WinExist(WinTitle . " ahk_id " . Win)
}
ScrollUp() {
global
If (isScollingUp)
Return
isScollingUp := True
Click, WheelUp
SetTimer, UnlockScrollUp, % throttleTimeoutMs
}
ScrollDown() {
global
If (isScollingDown)
Return
isScollingDown := True
Click, WheelDown
SetTimer, UnlockScrollDown, % throttleTimeoutMs
}
ScrollLeft() {
global
If (!hScrollActive || isScollingLeft)
Return
isScollingLeft := True
Click, WheelLeft
SetTimer, UnlockScrollLeft, % throttleTimeoutMs
}
ScrollRight() {
global
If (!hScrollActive || isScollingRight)
Return
isScollingRight := True
Click, WheelRight
SetTimer, UnlockScrollRight, % throttleTimeoutMs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment