Ok - I think I got it to work.
The idea here is to measure the time between two WheelUp actions. after the third WheelUp actio, time is compared between this click and last click, and is compared to the time between last click and the click before. If the time between last two clicks is much longer (3 times here) than the time between the clicks before, then the subroutine runs.
When testing, it appear to be a problem when a human suddenly goes from fast scrolling to slow scrolling, then the sub routine will most probably run, even if your initial purpose is to continue scrolling, just slower.
To overcome this problem, you can increase the scrollTimeIncreaseFactor.
Code: Select all
Global t ; Store last value for A_TickCount.
safeSpeedAbove_Delay_ms := 100 ; Disable calculation when mouse wheel speed is higher than 1/thisdelay (no unit for speed).
scrollTimeIncreaseFactor := 3 ; If the time between two click exceeds 3 times the time before last two click, activate
#Persistent
wheelup::
SetTimer, doSomethingAtEndOfScrolling, -500 ; ensures if scrolling suddenly stops (without speed decreasing) it still run the after-scrolling-routine (first intention for this timer)
; It also make sure that the doSomethingAtEndOfScrolling routine also runs after just one or two scrolls.
theOtherTaskIsAlreadyDone := 0 ; when 0, it doesn't prevent "doSomethingAtEndOfScrolling " from running.
soundbeep, 4000, 10
; Makes up history for timing between 3 last click, so being able to compare.
timeBetweenScrolls_last := timeBetweenScrolls
timeBetweenScrolls := timeBetweenCalls()
ToolTip, timeBetweenScrolls_last`t%timeBetweenScrolls_last%`ntimeBetweenScrolls`t%timeBetweenScrolls%
If (timeBetweenScrolls_last && timeBetweenScrolls) { ; Does not run the first or second time, when variable is'n set yet
;MsgBox, kommer hit
If ((timeBetweenScrolls > (timeBetweenScrolls_last * scrollTimeIncreaseFactor)) && ((timeBetweenScrolls_last > safeSpeedAbove_Delay_ms) || ( timeBetweenScrolls > safeSpeedAbove_Delay_ms))) {
; Doesn't run if last delay is much longer OR delay between scroll is less than safeSpeedAbove_Delay_ms
SetTimer, doSomethingAtEndOfScrolling, Off
GoSub, doSomethingAtEndOfScrolling
} Else ; delay between clicks is within limits.
; Updates the timer - it will run sooner, so the script shouldn't wait for the original timer that takes more than one second to start.
; This make sense if you roll the mouse wheel fast some times.
SetTimer, doSomethingAtEndOfScrolling, % timeBetweenScrolls_last * scrollTimeIncreaseFactor * 1.2
; ERROR - The SetTimer doesn't truly support expressions, I need to put a percent sign before the calculation.
} Else
SetTimer, doSomethingAtEndOfScrolling, -500
return
/*
wheeldown::
; put similar code here
return
*/
; if t is zero - it returns nothing.
timeBetweenCalls() {
if !t
t := A_TickCount
Else
u := A_TickCount - t
t := A_TickCount
Return u
}
doSomethingAtEndOfScrolling:
t := 0 ; clear timer
If theOtherTaskIsAlreadyDone ; Prevent sub from running twice at same hotkey.
Return
theOtherTaskIsAlreadyDone := 1
timeBetweenScrolls_last := 0 ; when this sub runs- that means you're done scrolling for now.
soundbeep, 3000, 500
ToolTip
SetTimer, doSomethingAtEndOfScrolling, Off
Return