Horizontal Scroll with Shift+MouseWheel in Windows 10 File Explorer

Post your working scripts, libraries and tools.
eugenesv
Posts: 171
Joined: 21 Dec 2015, 10:11

Horizontal Scroll with Shift+MouseWheel in Windows 10 File Explorer

Post by eugenesv » 30 Nov 2021, 03:50

I haven't found any solution to horizontal scrolling in File Explorer as it didn't react to any regular windows messages that more sane apps react to or other scrolling altrnatives I've found around, e.g. the previous topic ends up recommending a non-AHK solution QTTabBar :(, so I'm posting my solution that sends WM_HSCROLL events directly to the File Explorer's scrollbar control (if it exists) by its class name.
Feel free to suggest a better alternative!

(helper debug dbgTT, TT functions that warn about some mistakes are in a separate code block in the spoiler below, feel free to ignore them, but then remove them in the code above as well)
NB! This is AutoHotkey v2 syntax, works with the latest "beta.3"

Code: Select all

; Helper WinAPI constants
global dbg    	:= 1    	; Level of debug verbosity
  , msgScrollH	:= 0x0114	; WM_HSCROLL (=scrollbar button press, by line very slow, by page fast, might need to be sent to the control, not just the window), docs.microsoft.com/en-us/windows/win32/controls/wm-hscroll
  , scroll←Ln 	:= 0     	; SB_LINELEFT ; by one unit = click ←
  , scroll←Pg 	:= 2     	; SB_PAGELEFT ; by window's width = click on the scroll bar 
  , scroll→Ln 	:= 1     	; SB_LINERIGHT
  , scroll→Pg 	:= 3     	; SB_PAGERIGHT

; The scrolling function
FExpScrollH(FExpID:=0, Direction:="",ScrollUnit:="Ln", Rep:=1) {
  global msgScrollH, scroll←Ln,scroll←Pg,scroll→Ln,scroll→Pg

  RepMax	:= 20
  ; Delete these dbg helpers or copy the dbgTT/TT functions from a spoiler at the bottom of the post
  dbgTxt 	:= FExpID " = FExpID`n" Direction " = Direction" "`n" ScrollUnit " = ScrollUnit`n" Rep " = Rep"
  errDir 	:= "WARNING! Wrong Direction parameter" "`n" Direction " given, but should be" "`nL or" "`nR"
  errUnit	:= "WARNING! Wrong ScrollUnit parameter" "`n" ScrollUnit " given, but should be" "`nLn or" "`nPg"
  dbgTT(dbgMin:=1,   Text:=dbgTxt , Time:=2,id:=3,X:=1550,Y:=850)
  if (Direction!="L")   and (Direction!="R")
    dbgTT(dbgMin:=1, Text:=errDir , Time:=4,id:=2,x:=-1  ,y:=-1)
  if (ScrollUnit!="Ln") and (ScrollUnit!="Pg")
    dbgTT(dbgMin:=1, Text:=errUnit, Time:=4,id:=2,x:=-1  ,y:=-1)

  if not IsInteger(Rep) or (Rep < 1) {
    Rep := 1
  } else if (Rep > RepMax) {
    Rep := RepMax
  }
  dir := Direction= "L"  ? "←"  : "→"
  by  := ScrollUnit="Ln" ? "Ln" : "Pg"

  MouseGetPos(&mX, &mY, &mWinID, &mCtrlClassNN)
  FExpScrollBarClass	:= "ScrollBar1"
  if (FExpID = 0)                      ; No File Explorer Active
    Return
  scrollBarID         := ControlGetHwnd(FExpScrollBarClass, FExpID)
  if (scrollBarID = 0)                 ; No horizontal scrollbar
    Return

  Loop Rep {
    PostMessage(msgScrollH, scroll%dir%%by%, 0     , scrollBarID , FExpID)
      ;        (Msg       , wParam         , lParam, Control     , WinTitle, WinText, ExcludeTitle, ExcludeText)
      ; wParam (word is 16 bytes, so HIWORD can be set as 'x << 16')
        ; HIWORD: (only if LOWORD is SB_THUMBPOSITION/SB_THUMBTRACK) current position
        ; LOWORD: user's scrolling request
      ; lParam: scroll bar control's handle (if used); NULL if sent by a standard scroll bar
  }
}

; Not sure whether ~ and & are useful here, see my question here https://www.autohotkey.com/boards/viewtopic.php?f=82&t=97264

; you can make these work only in File Explorers' windows or the function above could also work in a more generic LShift+WheelUp combo that allows passing scroll events on hover if mouse is hovering over File Explorer
#HotIf WinActive("ahk_class CabinetWClass")	; only in File Explorer's windows
~Shift & WheelUp::{ ; Scroll left in File Explorer
  FExpID := WinActive("ahk_exe explorer.exe")
  ; comment out one of the two below
  Direction := "L", ScrollUnit := "Ln", Rep := 6 ; scroll by line, slow, but can adjust the number of lines in the Rep variable to make it faster
  Direction := "L", ScrollUnit := "Pg", Rep := 1 ; scroll by page, fast, but might be too fast
  FExpScrollH(FExpID, Direction, ScrollUnit, Rep)
}
~Shift & WheelDown::{ ; Scroll right in File Explorer
  FExpID	  := WinActive("ahk_exe explorer.exe")
  ; comment out one of the two below
  Direction := "R", ScrollUnit := "Ln", Rep := 6
  Direction := "R", ScrollUnit := "Pg", Rep := 1
  FExpScrollH(FExpID, Direction, ScrollUnit, Rep)
}
#HotIf
helper debug functions

likethevegetable
Posts: 81
Joined: 05 May 2021, 08:54

Re: Horizontal Scroll with Shift+MouseWheel in Windows 10 File Explorer

Post by likethevegetable » 01 Dec 2021, 08:50

My alternative: use a mouse like the Logitech MX Master or Anywhere 3 :P

eugenesv
Posts: 171
Joined: 21 Dec 2015, 10:11

Re: Horizontal Scroll with Shift+MouseWheel in Windows 10 File Explorer

Post by eugenesv » 03 Dec 2021, 04:01

likethevegetable wrote:
01 Dec 2021, 08:50
My alternative: use a mouse like the Logitech MX Master or Anywhere 3 :P
That's a worse alternative ;) , the better one would be not to use this dumb File Explorer in the first place :P

Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

Re: Horizontal Scroll with Shift+MouseWheel in Windows 10 File Explorer

Post by Skrell » 30 May 2022, 10:01

Would someone kindly translate this to a <2.0 solution?

Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

Re: Horizontal Scroll with Shift+MouseWheel in Windows 10 File Explorer

Post by Skrell » 31 May 2022, 21:29

Any idea why this doesn't seem to work?

Code: Select all

            If (wClass == "CabinetWClass")
            {
                If (Lines < 0)
                    Loop %Iterations%
                        PostMessage, 0x114, 0, 0, "ScrollBar1", "ahk_class CabinetWClass"
                Else
                    Loop %Iterations%
                        PostMessage, 0x114, 1, 0, "ScrollBar1", "ahk_class CabinetWClass"
            }

Post Reply

Return to “Scripts and Functions (v2)”