Scroll Explorer on middle mouse button drag

Post your working scripts, libraries and tools for AHK v1.1 and older
aph
Posts: 7
Joined: 29 Jan 2018, 21:53

Scroll Explorer on middle mouse button drag

02 Feb 2018, 22:05

This script makes Explorer scroll like Chrome and other windows when middle clicked.

Code: Select all

; Description: Scroll Explorer on middle mouse button drag
; Permalink: https://autohotkey.com/boards/viewtopic.php?t=43715
; Author: aph
; Version: 0.2
$*MButton::
    MouseGetPos, CursorX, CursorY, Window, ClassNN
    WinGetTitle, Title, ahk_id %Window%
    WinGetClass, ahk_class, ahk_id %Window%
    WinGet ahk_exe, ProcessName, ahk_id %Window%
    WinGet ahk_PID, PID, ahk_id %Window%
    WinGetText, VisibleText, ahk_id %Window%
    MouseGetPos, CursorX_ended, CursorY_ended, Window_ended, ClassNN_ended
    WinGetClass, ahk_class_ended, ahk_id %Window_ended%
    WinGet ahk_exe_ended, ProcessName, ahk_id %Window_ended%
    AllowedApp := ahk_exe = "explorer.exe" or ahk_exe = "mmc.exe" or ahk_exe = "systempropertiesadvanced.exe" or ahk_exe = "filezilla.exe" or ahk_exe = "7zFM.exe"
    AllowedText := InStr(VisibleText, "Tree View") or InStr(VisibleText, "FolderView")
    LimitedApp := ahk_exe = "cmd.exe"
    DisabledApp := ahk_class_ended = "Shell_TrayWnd" or ahk_class_ended = "WorkerW"
    if (AllowedText >= 1)
        AllowedText = 1
    If (DisabledApp) {
        SendInput, {MButton Down}
        Return
    }
    Else If (!AllowedApp and !LimitedApp and !AllowedText) {
        SendInput, {MButton Down}
        Return
    }
    Else {
        If (AllowedApp) {
            SendInput, {MButton}
        }
        MiddleScroll := 1
        SetSystemCursor("SIZEALL")
        Sensitivity = 10 ; How far the middle mouse wheel has to be dragged before scrolling is triggered
        MouseGetPos, X1, Y1, , c, 2
        OrigTimer := 50 ; How quickly the file list scrolls
        SetTimer, MBScroll, %OrigTimer%
        MBScroll:
            MouseGetPos, X2, Y2
            Distance := Abs(Y2-Y1)
            If (Distance >= Sensitivity) {
                Rounded := % Round((Distance / 200)**1.25+1)
                DllCall("SystemParametersInfo", UInt, 0x69, UInt, Round(Ln(Rounded)+1), UInt, 0, UInt, 0) ; Vary lines scrolled by distance of drag 
                Timer := Round(OrigTimer - (OrigTimer/2*Percent/100))
                SetTimer, MBScroll, %Timer%
                Percent := (A_ScreenHeight - (Max(Y1, Abs(Y1-A_ScreenHeight)) - Distance)) / A_ScreenHeight * 100
                SendInput, % "{Blind}{Wheel" (Y2 > Y1 ? "Down" : "Up") " " Rounded "}"
            }
        Return
        $*MButton Up::
            DllCall("SystemParametersInfo", UInt, 0x69, UInt, 3, UInt, 0, UInt, 0) ; Set back to 3 lines scrolled
            SetTimer, MBScroll, off
            SetSystemCursor()
            MiddleScroll := 0
            SendInput {MButton Up}
            SetSystemCursor(Cursor="") {
                SystemCursors := "32512IDC_ARROW|32513IDC_IBEAM|32514IDC_WAIT|32515IDC_CROSS|32516IDC_UPARROW|32642IDC_SIZENWSE|32643IDC_SIZENESW|32644IDC_SIZEWE|32645IDC_SIZENS|32646IDC_SIZEALL|32648IDC_NO|32649IDC_HAND|32650IDC_APPSTARTING|32651IDC_HELP"
                If (Cursor = "")
                    Return DllCall("SystemParametersInfo", "UInt", 0x57, "UInt", 0, "UInt", 0, "UInt", 0) 
                If (StrLen(SystemCursors) = 221)
                    Loop, Parse, SystemCursors, |
                        StringReplace, SystemCursors, SystemCursors, %A_LoopField%, % DllCall("LoadCursor", "UInt", 0, "Int", SubStr(A_LoopField, 1, 5)) A_LoopField
                If !(Cursor := SubStr(SystemCursors, InStr(SystemCursors "|", "IDC_" Cursor "|") - 5 - p := (StrLen(SystemCursors) - 221) / 14, 5))
                    MsgBox, 262160, %A_ScriptName% - %A_ThisFunc%(): Error, Invalid cursor name!
                Else
                    Loop, Parse, SystemCursors, |
                        DllCall("SetSystemCursor", "UInt", DllCall("CopyIcon", "UInt", Cursor), "Int", SubStr(A_LoopField, 6, p))
                }
        Return
    }
Return
Last edited by aph on 06 Feb 2018, 18:47, edited 2 times in total.
aph
Posts: 7
Joined: 29 Jan 2018, 21:53

Re: Scroll Explorer on middle mouse button drag

06 Feb 2018, 17:07

Updates:
  • 0.2:
    • Focus on controls within Explorer
    • Disable on taskbar and desktop
    • Stop dragging as soon as middle button is released, regardless if scrolling has started or not
    • Add support for:
      • Old-style open/save dialogs and other types of Explorer windows
      • MMC based dialogs (Event Viewer, Services, Group/Security Policy, Computer Management, etc.)
      • Advanced system settings / System Properties
      • Override default command prompt middle drag since it's too slow
      • 7-Zip
      • FileZilla
Last edited by aph on 06 Feb 2018, 19:26, edited 4 times in total.
User avatar
Cerberus
Posts: 172
Joined: 12 Jan 2016, 15:46

Re: Scroll Explorer on middle mouse button drag

06 Feb 2018, 17:18

Very interesting, cool idea!
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Scroll Explorer on middle mouse button drag

07 Feb 2018, 07:19

This is actually pretty smart! I would make some adjustments to make it a bit smoother but I don't have enough time I'm afraid :(

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

aph
Posts: 7
Joined: 29 Jan 2018, 21:53

Re: Scroll Explorer on middle mouse button drag

11 Feb 2018, 06:49

You mean in the style talked about in these threads?
If so, I should be able to get that working.

Right now testing exclusions for toolbars, using less exe-specific inclusions and adding more dialogs that browse files.
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Scroll Explorer on middle mouse button drag

11 Feb 2018, 18:19

Well, I'll tell you one thing;
Instead of doing something like this:

Code: Select all

If (Var = "Info") || (Var = "Data") || (Var = "Name")
Do something like:

Code: Select all

If (Var ~= "i)Info|Data|Name") ; 'i)' means that it ignores the case and looks for the characters (Lowercase or upper)
It's short, simple, and quick to manipulate.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

Ochado
Posts: 1
Joined: 23 Jan 2020, 14:42

Re: Scroll Explorer on middle mouse button drag

23 Jan 2020, 14:53

Thanks so much for this! I've been looking for this kind of solution for around one month now.

Your script works great on my laptop (HP ZBook 17 G6) except that there is a bug in it: the line that declares Percent should precede the line that declares Timer. That is, instead of:

Code: Select all

                Timer := Round(OrigTimer - (OrigTimer/2*Percent/100))
                SetTimer, MBScroll, %Timer%
                Percent := (A_ScreenHeight - (Max(Y1, Abs(Y1-A_ScreenHeight)) - Distance)) / A_ScreenHeight * 100
the corrected code should be:

Code: Select all

                Percent := (A_ScreenHeight - (Max(Y1, Abs(Y1-A_ScreenHeight)) - Distance)) / A_ScreenHeight * 100
                Timer := Round(OrigTimer - (OrigTimer/2*Percent/100))
                SetTimer, MBScroll, %Timer%
After fixing that, the script works great. Of course, I also had to customize the line with ahk_exe to add the applications that I care about.
umam99
Posts: 1
Joined: 16 Jun 2022, 09:12

Re: Scroll Explorer on middle mouse button drag

16 Jun 2022, 09:15

Hello, does anyone here knows how to slow it down? Its still too fast. I want it to be like when scrolling on browser
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: Scroll Explorer on middle mouse button drag

17 Jun 2022, 08:23

Modify the line:
OrigTimer := 50 ; How quickly the file list scrolls (the bigger the slower)
Start with value 200 or so...
Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

Re: Scroll Explorer on middle mouse button drag

22 Jun 2022, 10:20

Shame horizontal scroll doesn't seem to work in Win10... :-/
foodi
Posts: 3
Joined: 18 Apr 2023, 17:55

Re: Scroll Explorer on middle mouse button drag

18 Apr 2023, 18:24

Was looking for someone to have addressed this functionality in the windows file explorer, and thrilled to find this thread!
The script works great on Windows 11, except I would like to exclude certain apps from the effect of the script. Specifically, Blender.exe

I noticed this set of lines in the code, which i'm assuming are pertinent:

Code: Select all

    AllowedApp := ahk_exe = "explorer.exe" or ahk_exe = "mmc.exe" or ahk_exe = "systempropertiesadvanced.exe" or ahk_exe = "filezilla.exe" or ahk_exe = "7zFM.exe"
    AllowedText := InStr(VisibleText, "Tree View") or InStr(VisibleText, "FolderView")
    LimitedApp := ahk_exe = "cmd.exe"
    DisabledApp := ahk_class_ended = "Shell_TrayWnd" or ahk_class_ended = "WorkerW"
I tried adding appending to the LimitedApp line, like so

Code: Select all

LimitedApp := ahk_exe = "cmd.exe" or ahk_class = "blender.exe"

and also tried adding to the DisabledApp line, like so

Code: Select all

DisabledApp := ahk_class_ended = "Shell_TrayWnd" or ahk_class_ended = "WorkerW" or ahk_class_ended = "Blender"
..with no success.

Can anyone advise?

What is the difference between a "Limited" app and a "Disabled" app?
foodi
Posts: 3
Joined: 18 Apr 2023, 17:55

Re: Scroll Explorer on middle mouse button drag

24 Apr 2023, 13:46

Is there no one around who can assist me with this?

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: IfThenElse, imustbeamoron and 140 guests