Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Flowgun/e478b9988b21245aebdef5e1adf50b8c to your computer and use it in GitHub Desktop.
Save Flowgun/e478b9988b21245aebdef5e1adf50b8c to your computer and use it in GitHub Desktop.
Accelerated Scrolling v1.5
/* ; _____________________________________________________________________________
; Improved Accelerated Scrolling By Flowgun
; original Accelerated Scrolling: V1.3 By BoffinbraiN
; Major Changes (v1.5):
; - Reloading at Logon/unlocking: The mouse hook can get
; released when the session is locked/closed. Now the
; script reloads itself to rehook the ScrollWheel hotkeys
; - changed the default acceleration values.
; Major Changes (v1.4):
; - This Script no longer interfers with other scripts, so
; it'll work and keep the assignements of Mouse Wheel
; in other scripts working.
; - Added a couple of functions to help in adding exceptions
; based on the class or on the Process name of apps.
; You can use "Window Spy" to figure them out.
___________________________________________________________________________________
*/
ListLines Off
#NoEnv
SetBatchLines -1
#SingleInstance
#Persistent
#MaxHotkeysPerInterval 120
;Process, Priority, , H
SendMode Input
; Show scroll velocity as a tooltip while scrolling. 1 or 0.
tooltips := 0
; The length of a scrolling session.
; Keep scrolling within this time to accumulate boost.
; Default: 500. Recommended between 400 and 1000.
timeout := 500
; If you scroll a long distance in one session, apply additional boost factor.
; The higher the value, the longer it takes to activate, and the slower it accumulates.
; Set to zero to disable completely. Default (BoffinbraiN): 30. Default (Flowgun): 60
boost := 60
; Spamming applications with hundreds of individual scroll events can slow them down.
; This sets the maximum number of scrolls sent per click, i.e. max velocity.
; Default(BoffinbraiN): 60. Default (Flowgun): 40
limit := 40
; Runtime variables. Do not modify.
distance := 0
vmax := 1
;; ----------------------------------------
;; -------- Exceptions ----------
;; ----------------------------------------
;; If the scrolling is too fast in certain apps,
;; use "MouseIsOverClass()" or "MouseIsOverEXE()" to add exceptions.
;; make sure to uncomment the starting #if and the ending #if (after
;; the hotkeys) to use these exceptions.
;;; Starting if:
; #if !( MouseIsOverClass() or MouseIsOverEXE())
; ----------------------------------------
; -------- Key bindings ------
; ----------------------------------------
;;;------- Functionality ---------
~WheelUp:: Scroll("WheelUp")
~WheelDown:: Scroll("WheelDown")
;;;------- Additional Hotkeys ----
; #WheelUp:: Suspend
; #WheelDown:: Goto Quit
; ----------------------------------------
; ----------------------------------------
;;; ending if:
; #if
Scroll(MouseWheel){
Global
t := A_TimeSincePriorHotkey
if (A_PriorHotkey = A_ThisHotkey && t < timeout){
; tooltip, hehe
; Remember how many times we've scrolled in the current direction
distance++
; Calculate acceleration factor using a 1/x curve
v := (t < 80 && t > 1) ? (250.0 / t) - 1 : 1
; Apply boost
if (boost > 1 && distance > boost){
; Hold onto the highest speed we've achieved during this boost
if (v > vmax)
vmax := v
else
v := vmax
v *= distance / boost
}
; Validate
v := (v > 1) ? ((v > limit) ? limit : Floor(v)) : 1
if (v > 1 && tooltips)
QuickToolTip("×"v, timeout)
MouseClick, %MouseWheel%, , , v - 1
} else {
; Combo broken, so reset session variables
distance := 0
vmax := 1
}
return
}
Quit:
QuickToolTip("Exiting Accelerated Scrolling...", 1000)
Sleep 1000
ExitApp
QuickToolTip(text, delay) {
ToolTip, %text%
SetTimer ToolTipOff, %delay%
return
ToolTipOff:
SetTimer ToolTipOff, Off
ToolTip
return
}
; ----------------------------------------
; ----------------------------------------
; These functions return true if the Class or the Process name match
; --------------------------
MouseIsOverClass(TheClass){
MouseGetPos,,,WinID
WinGetClass, WinClass, ahk_id %WinID%
return WinClass=TheClass
}
; ---------------------------
MouseIsOverEXE(TheEXE){
MouseGetPos,,,WinID
WinGet, WinEXE, ProcessName, ahk_id %WinID%
; tooltip, % WinEXE
return WinEXE=TheEXE ; ends up returning true if they are equal, else false if they are not equal
}
; ====================================================
; ************ Reload at Logon *************
; ====================================================
;; original post: https://www.autohotkey.com/boards/viewtopic.php?t=48250
WM_WTSSESSION_CHANGE(wParam, lParam, Msg, hWnd){
static init:=(DllCall( "Wtsapi32.dll\WTSRegisterSessionNotification", UInt, A_ScriptHwnd, UInt, 1) && OnMessage(0x02B1, "WM_WTSSESSION_CHANGE"))
,_:={base:{__Delete: "WM_WTSSESSION_CHANGE"}}
if !(_)
DllCall("Wtsapi32.dll\WTSUnRegisterSessionNotification", "UInt", hWnd)
If (wParam=0x5 || wParam=0x8)
SetTimer,LogonReload,-100
Return
LogonReload:
reload
Return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment