Automatic scroll wheel

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Elaphe666
Posts: 131
Joined: 28 Nov 2015, 11:39

Automatic scroll wheel

Post by Elaphe666 » 06 Jul 2017, 04:57

Hi. I've come across this handy script that make mouse wheel scrolling automatic, which can be interesting for browsing large picture galleries. However, I'd like to modify it to be able to adjust the scrolling speed with the wheel. Would this be possible?

Code: Select all

#singleinstance force

wheeling := 0

WheelUp::
WheelDown::
	if (!wheeling)
	{
		wheeling := 1
		SetTimer Wheely, 200
	}
	else
	{
		wheeling := 0
		SetTimer Wheely, Off
	}

Wheely:
	MouseClick %A_ThisHotkey%

wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Automatic scroll wheel

Post by wolf_II » 06 Jul 2017, 05:39

Try this:

Code: Select all

#NoEnv
#SingleInstance, Force
bWheel := False
Period := 250
Return ; end of auto-execute section


WheelUp::   ; start auto-scrolling
WheelDown:: ; start auto-scrolling
    bWheel := True
    Key := A_ThisHotkey
    SetTimer, Wheeler, %Period%
Return


Wheeler: ; timer controlled
    ToolTip, %Period%, 0, 0
    Send, {%Key%}
Return


#If bWheel ; context

    Esc:: ; stop auto-scrolling
        bWheel := False
        ToolTip ; off
        SetTimer, Wheeler, Off
    Return

    NumpadAdd:: ; go faster
        If (Period -= 50) < 50
            Period := 50
        SetTimer, Wheeler, %Period%
    Return

    NumpadSub:: ; go slower
        If (Period += 50) > 1000
            Period := 1000
        SetTimer, Wheeler, %Period%
    Return

#If ; end of context
I hope that helps.

Elaphe666
Posts: 131
Joined: 28 Nov 2015, 11:39

Re: Automatic scroll wheel

Post by Elaphe666 » 06 Jul 2017, 10:13

That works great. Thank you. However, my idea was to be able to control the speed with the scrollwheel itself.

wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Automatic scroll wheel

Post by wolf_II » 06 Jul 2017, 10:40

Try this:

Code: Select all

#NoEnv
#SingleInstance, Force
bWheel := False
Period := 250
Return ; end of auto-execute section


Wheeler: ; timer controlled
    ToolTip, %Period%, 0, 0
    Send, {%Key%}
Return


;-------------------------------------------------------------------------------
#If Not bWheel ; context
;-------------------------------------------------------------------------------

    WheelUp::   ; start auto-scrolling
    WheelDown:: ; start auto-scrolling
        bWheel := True
        Key := A_ThisHotkey
        SetTimer, Wheeler, %Period%
    Return


;-------------------------------------------------------------------------------
#If bWheel ; other context
;-------------------------------------------------------------------------------

    WheelUp::
    WheelDown::
        If (Key = A_ThisHotkey) {   ; same direction -> go faster
            If (Period -= 50) < 50
                Period := 50
        } Else                      ; other direction -> go slower
            If (Period += 50) > 1000
                Period := 1000
        SetTimer, Wheeler, %Period%
    Return

    Esc:: ; stop auto-scrolling
        bWheel := False
        ToolTip ; off
        SetTimer, Wheeler, Off
    Return


;-------------------------------------------------------------------------------
#If ; end of context
;-------------------------------------------------------------------------------
I hope that helps.

Elaphe666
Posts: 131
Joined: 28 Nov 2015, 11:39

Re: Automatic scroll wheel

Post by Elaphe666 » 06 Jul 2017, 11:34

Wow, that's pretty impressive! The only problem I've found with this script is changing the direction of the scroll. For instance, I start scrolling down a text file or switching between pictures with ACDSee and I can accelerate or decelerate, but not stop the scroll and use scroll up to scroll in the oposite direction.

wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Automatic scroll wheel

Post by wolf_II » 06 Jul 2017, 11:43

Try this:

Code: Select all

; AutoScroll.ahk   attempt#3

#NoEnv
#SingleInstance, Force
bWheel := False
Period := 250
Return ; end of auto-execute section


Wheeler: ; timer controlled
    ToolTip, %Period%, 0, 0
    Send, {%Key%}
Return


;-------------------------------------------------------------------------------
#If Not bWheel ; context
;-------------------------------------------------------------------------------

    WheelUp::   ; start auto-scrolling
    WheelDown:: ; start auto-scrolling
        bWheel := True
        Key := A_ThisHotkey
        SetTimer, Wheeler, %Period%
    Return


;-------------------------------------------------------------------------------
#If bWheel ; other context
;-------------------------------------------------------------------------------

    WheelUp::
    WheelDown::
        If (Key = A_ThisHotkey) {   ; same direction -> go faster
            If (Period -= 50) < 50
                Period := 50
        } Else                      ; other direction -> go slower
            If (Period += 50) > 500 {
                bWheel := False
                ToolTip ; off
                Period := "Off"
            }
        SetTimer, Wheeler, %Period%
    Return

    Esc:: ; stop auto-scrolling
        bWheel := False
        ToolTip ; off
        SetTimer, Wheeler, Off
    Return


;-------------------------------------------------------------------------------
#If ; end of context
;-------------------------------------------------------------------------------
I hope that helps. I have not tested much yet, though. Adjust maximum value for Period (currently 500).

Rabbit23
Posts: 1
Joined: 25 May 2022, 09:09

Re: Automatic scroll wheel

Post by Rabbit23 » 25 May 2022, 12:24

@wolf_II

Hey, was wondering if you'd be able to land a hand with this.

I am using this code below but it needs a bit of tweaking.

I am trying to accomplish a infinite loop that slowly scrolls all the way to the bottom and it rests at the bottom and after 20-30 seconds it slowly scrolls back to the top and does that infinite amount of times. So a infinite loop would be needed I am guessing that would get this to work.

Pasted the code below:

Code: Select all

#NoEnv
#SingleInstance, Force
bWheel := False
Period := 700
Return ; end of auto-execute section


WheelUp::   ; start auto-scrolling
WheelDown:: ; start auto-scrolling
    bWheel := True
    Key := A_ThisHotkey
    SetTimer, Wheeler, %Period%
Return


Wheeler: ; timer controlled
    ToolTip, %Period%, 0, 0
    Send, {%Key%}
Return


#If bWheel ; context

    Esc:: ; stop auto-scrolling
        bWheel := False
        ToolTip ; off
        SetTimer, Wheeler, Off
    Return

    NumpadAdd:: ; go faster
        If (Period -= 50) < 50
            Period := 50
        SetTimer, Wheeler, %Period%
    Return

    NumpadSub:: ; go slower
        If (Period += 50) > 1000
            Period := 1000
        SetTimer, Wheeler, %Period%
    Return

#If ; end of context
[Mod edit: [code][/code] tags added.]
Last edited by gregster on 25 May 2022, 12:30, edited 1 time in total.
Reason: Please use code tags when posting code. Thank you!

Post Reply

Return to “Ask for Help (v1)”