Skip to content

Instantly share code, notes, and snippets.

@jasonsparc
Last active February 15, 2024 21:16
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasonsparc/7cc1f2317aa9125dbd63e0bb5f3da0c6 to your computer and use it in GitHub Desktop.
Save jasonsparc/7cc1f2317aa9125dbd63e0bb5f3da0c6 to your computer and use it in GitHub Desktop.
AutoHotkey, Accelerated Scrolling v1.3, By BoffinbraiN
; Accelerated Scrolling
; V1.3
; By BoffinbraiN
#NoEnv
#SingleInstance
#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: 30.
boost := 30
; 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: 60.
limit := 60
; Runtime variables. Do not modify.
distance := 0
vmax := 1
; Key bindings
WheelUp:: Goto Scroll
WheelDown:: Goto Scroll
#WheelUp:: Suspend
#WheelDown:: Goto Quit
Scroll:
t := A_TimeSincePriorHotkey
if (A_PriorHotkey = A_ThisHotkey && t < timeout)
{
; 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, %A_ThisHotkey%, , , v
}
else
{
; Combo broken, so reset session variables
distance := 0
vmax := 1
MouseClick %A_ThisHotkey%
}
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
}
@jasonsparc
Copy link
Author

@Aurasphere-au
Copy link

Aurasphere-au commented Feb 12, 2024

Great work!
Is it possible to add a qualifier that doubles (or whatever) the scroll factor?
Is it possible to update to V2?

@jasonsparc
Copy link
Author

jasonsparc commented Feb 15, 2024

@Aurasphere-au :

Great work!

Actually, I didn't create the script. See the linked forum post instead.
I simply saved it in a gist – I also no longer fully remember why I did that.


Also, it's been years since I last used this script. I barely know how it works now.

However, with modern AHK, I do believe that the above can be a achieved using a much simpler logic:

In AHK v1 for example, you could do,

WheelUp::
Click % "WheelUp " (GetScrollLines() * A_EventInfo)
return

WheelDown::
Click % "WheelDown " (GetScrollLines() * A_EventInfo)
return

GetScrollLines() {
	; https://autohotkey.com/board/topic/8435-mouse-wheel-speed/
	; https://msdn.microsoft.com/en-us/library/windows/desktop/ms724947(v=vs.85).aspx
	;
	; retrieve original vertical scroll wheel setting
	; #define SPI_GETWHEELSCROLLLINES    0x68
	DllCall("SystemParametersInfo", UInt, 0x68, UInt, 0, UIntP, Scroll_Lines, UInt, 0) 
	return Scroll_Lines
}

Notice how the above script is actually much shorter and simpler. Also notice how A_EventInfo is used here. You could multiply that to itself (i.e., A_EventInfo * A_EventInfo) to achieve accelerated scrolling, and even keep multiplying that further if you want even more acceleration. See the docs in, A_EventInfo | Variables and Expressions - Definition & Usage | AutoHotkey v1

NOTE: A_EventInfo is 1 if you scroll the wheel slowly, but it'll become 2 or greater if you scroll the wheel fast. Thus we could simply multiply A_EventInfo to itself to achieve accelerated scrolling when the mouse wheel is scrolled fast.

See also, Mouse Wheel Hotkeys | Hotkeys - Definition & Usage | AutoHotkey v1

Now I barely used AHK v2, so I won't be able to help you port the above to v2. I mainly used v1 for most of my scripts, but I'm also planning to migrate all my scripts to v2 eventually. After all, if it ain't broke (yet), don't fix it :P

However, given the simplicity of the newly proposed script, I believe you could port it easily to v2. Just look up the docs, try the "get started" page, and ask help in the forums if you have trouble. Perhaps even, someone in the forums would be happy to do the whole work for you without you even requiring to read up an AHK documentation.

@Aurasphere-au
Copy link

Cool...well thanks for your considered reply

That all helps greatly. As Im getting older Im realisng some of the RSI on my hands and wrist; but also the benefits of muscle mem. So acceleration and mutlimode is foremost atm. Forking any motion that is navigationally up and down from the scroll wheel with qualirifers/context as well as accel control is my aim.

  1. Accel and quantity multiplier
  2. Alternate context/qual conversion of scroll to listbox up and down
    etc

Cheers Jason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment