Windows Explorer folder positions and scrolling

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
illuzioner
Posts: 27
Joined: 07 Jun 2017, 13:50

Windows Explorer folder positions and scrolling

21 Jun 2017, 10:10

While I've played around with AutoHotkey for a few weeks, there's lots I don't know how to do. However, two things continuously bother me about Windows Explorer that I really want to change:

1) The scrollbar scrolls the currently selected portion of the window (tree view or content view) rather than the portion over which the mouse hovers
2) When I open a folder in the content view (RHS), the folder list places the current folder at the bottom of the tree view rather than positioning it at the top.

Is it possible change these behaviors with AutoHotkey?

Can people offer me some suggestions on how to approach these issues, or recommend scripts and libraries that might help or already have implemented them?

Thank you all for the help.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Windows Explorer folder positions and scrolling

22 Jun 2017, 02:58

I don't usually use the treeview pane, but I thought it was an interesting problem so I gave it a shot.

I managed to create a script that works, but I needed to use the Acc library to scroll the main pane, when the treeview pane was focused. [EDIT: the script has been edited to not need Acc any more, with the Acc lines commented out]
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

I'm not sure about the location of the folder, although a possibility is adding a GUI element that you could click, or a hotkey, to scroll to that item in the treeview.

Code: Select all

#IfWinActive, ahk_class CabinetWClass
$WheelDown:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
$WheelUp:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
#IfWinActive, ahk_class ExploreWClass
$WheelDown:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
$WheelUp:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
ControlGetFocus, vCtlClassNN1, A
MouseGetPos,,,, vCtlClassNN2
if ((vCtlClassNN1 = "SysTreeView321") && (vCtlClassNN2 = "DirectUIHWND3"))
{
	;ControlGet, hCtl, Hwnd,, ScrollBar2, A
	;oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
	;Loop, 2
	;	oAcc.accDoDefaultAction(InStr(A_ThisHotkey, "Up") ? 1 : 5)
	;oAcc := ""
	;SB_PAGEDOWN := 3 ;SB_PAGEUP := 2
	PostMessage, 0x115, % InStr(A_ThisHotkey, "Up") ? 2 : 3, 0, ScrollBar2, A ;WM_VSCROLL := 0x115
}
else if ((vCtlClassNN2 = "SysTreeView321") && (vCtlClassNN1 = "DirectUIHWND3"))
	ControlSend, % vCtlClassNN2, % InStr(A_ThisHotkey, "Up") ? "{PgUp}" : "{PgDn}", A
else
	SendInput, % InStr(A_ThisHotkey, "Up") ? "{WheelUp}" : "{WheelDown}"
ToolTip % "foc: " vCtlClassNN1 "`r`n" "und: " vCtlClassNN2
return
#IfWinActive
Last edited by jeeswg on 25 Jun 2017, 04:32, edited 2 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Windows Explorer folder positions and scrolling

22 Jun 2017, 08:36

I thought I'd try sending PgDn to all controls (while the SysTreeView32 control was the active control), to see if ControlSend would work on any control. It did work if you sent PgDn to the ScrollBar2 control, however, it didn't then show the selected file at the bottom of the visible area as it normally does when you send PgDn to the window.

tl;dr
ControlSend, ScrollBar2, {PgDn}, A works (to scroll file list even when treeview is active), but it looks a bit weird.

Code: Select all

q:: ;send PgDn to all controls
WinGet, hWnd, ID, A
WinGet, vCtlList, ControlList, % "ahk_id " hWnd
Loop, Parse, vCtlList, `n
{
	if 0 && (A_Index < 20)
		continue
	if (A_LoopField = "ScrollBar2")
		continue
	ControlSend, % A_LoopField, {PgDn}, % "ahk_id " hWnd
	ToolTip, % A_Index " " A_LoopField
	Sleep 300
	;Sleep 700
}
MsgBox, % "done"
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
illuzioner
Posts: 27
Joined: 07 Jun 2017, 13:50

Re: Windows Explorer folder positions and scrolling

22 Jun 2017, 12:06

Wow, thanks for doing this!

The behavior isn't quite what I was hoping for. Right now it just scrolls in the opposite pane of the selected pane (I'm on Win 7 too), but won't scroll in the pane under the mouse.

I think this might be an alternative way of achieving that:
1) On wheel up or down, store the pane with focus
2) give focus to the pane under the mouse, if different
3) allow the wheel up/down to continue through
4) return focus to the pane from #1 (this step may not be necessary)

What do you think of this approach?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Windows Explorer folder positions and scrolling

22 Jun 2017, 12:40

When I tested I had: SysTreeView321 for the treeview, and DirectUIHWND3 for the main pane. Are you getting the same ClassNNs? Whatever I had focused, it scrolled the pane underneath.

I did consider using ControlFocus as a Plan B. On the basis that for some reason the user would not want the control focus to change, I avoided doing it, but your approach seems fine.

[EDIT:] This script assumes the window is active. So that might be an issue. Thought I'd mention that just in case, MouseGetPos can get the hWnd of the window under the cursor, which can be used to adjust the script to make it more versatile, to handle multiple and inactive windows.

==================================================

These also work well for scrolling the file pane regardless of which control is focused.

Code: Select all

q::
PostMessage, 0x115, 2, 0, ScrollBar2, A ;WM_VSCROLL := 0x115 ;SB_PAGEUP := 2
return

w::
PostMessage, 0x115, 3, 0, ScrollBar2, A ;WM_VSCROLL := 0x115 ;SB_PAGEDOWN := 3
return
SB constants listed here:
Scrolling inactive window - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 50#p154950
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
illuzioner
Posts: 27
Joined: 07 Jun 2017, 13:50

Re: Windows Explorer folder positions and scrolling

24 Jun 2017, 12:34

Thank you again. Yes, I was getting the same class names as you. In my case, though, it was the opposite of the selected pane that scrolled when the mouse hovered over it.

I understand your reluctance to change focus, I was reluctant too, but considered it a viable alternative. I'm aware of the ControlFocus command, but how do I set that given the classes you mentioned?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Windows Explorer folder positions and scrolling

25 Jun 2017, 04:44

I have edited my earlier script to use WM_VSCROLL and not need the Acc library (commenting out the original Acc lines).

==================================================

I'm not sure why you're getting the opposite result, you could try and use ToolTips or some other means, to work out what's happening.

However, I did see something a bit like the behaviour you described: if I had the treeview focused, and used WheelUp/WheelDown while the cursor was over the file list, the file list scrolled, if I then moved over a nearby control, that was not the file pane control or treeview, and then used WheelUp/WheelDown, the treeview (as it was still the focused control) would scroll. So although that was the behaviour that was expected, it's perhaps undesirable.

The script could store the last control that it scrolled, in a variable, and scroll that control whenever WheelUp/WheelDown is used, that variable's value would be changed whenever it detects one of the 2 controls it's looking for, under the cursor. Alternatively the ControlFocus approach could be a good option ...

==================================================

I have rewritten the script from earlier using ControlFocus. You might like to have a go at editing the original script to try and recreate this script yourself before checking my script.

Code: Select all

;using ControlFocus to set the control focus

#IfWinActive, ahk_class CabinetWClass
$WheelDown:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
$WheelUp:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
#IfWinActive, ahk_class ExploreWClass
$WheelDown:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
$WheelUp:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
ControlGetFocus, vCtlClassNN1, A
MouseGetPos,,,, vCtlClassNN2
if ((vCtlClassNN1 = "SysTreeView321") && (vCtlClassNN2 = "DirectUIHWND3"))
|| ((vCtlClassNN2 = "SysTreeView321") && (vCtlClassNN1 = "DirectUIHWND3"))
	ControlFocus, % vCtlClassNN2, A
SendInput, % InStr(A_ThisHotkey, "Up") ? "{WheelUp}" : "{WheelDown}"
ToolTip % "foc: " vCtlClassNN1 "`r`n" "und: " vCtlClassNN2
return
#IfWinActive
Here is a slight variant, what it does is: it doesn't actually consume the WheelUp/WheelDown presses, but it lets them take place, and checks/sets the control at the same time:

Code: Select all

;using ControlFocus to set the control focus

#IfWinActive, ahk_class CabinetWClass
~WheelDown:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
~WheelUp:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
#IfWinActive, ahk_class ExploreWClass
~WheelDown:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
~WheelUp:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
ControlGetFocus, vCtlClassNN1, A
MouseGetPos,,,, vCtlClassNN2
if ((vCtlClassNN1 = "SysTreeView321") && (vCtlClassNN2 = "DirectUIHWND3"))
|| ((vCtlClassNN2 = "SysTreeView321") && (vCtlClassNN1 = "DirectUIHWND3"))
	ControlFocus, % vCtlClassNN2, A
ToolTip % "foc: " vCtlClassNN1 "`r`n" "und: " vCtlClassNN2
return
#IfWinActive
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
illuzioner
Posts: 27
Joined: 07 Jun 2017, 13:50

Re: Windows Explorer folder positions and scrolling

27 Jun 2017, 09:47

The first script doesn't work at all for me, for some reason. Nothing scrolls in either pane, regardless of what's selected. Not sure what's going on there or what the difference is between our systems.

The second script, however, works great! Yes, it deselects the pane and file selection, but overall I like it much better.

Thanks for the great help!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Windows Explorer folder positions and scrolling

27 Jun 2017, 10:03

Cheers. Hmm, Admin mode maybe? I really don't know why it wouldn't be working, in case anyone has any suggestions.

You can always try this just in case:

Code: Select all

#IfWinActive, ahk_class CabinetWClass
$WheelDown::
$WheelUp::
#IfWinActive, ahk_class ExploreWClass
$WheelDown::
$WheelUp::
;MsgBox, % A_ThisHotkey
ToolTip, % A_Now " " A_Msec " " A_ThisHotkey
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
illuzioner
Posts: 27
Joined: 07 Jun 2017, 13:50

Re: Windows Explorer folder positions and scrolling

27 Jun 2017, 11:21

Yes, it's confusing to me too. I have admin privileges, but don't act as admin or superuser.

I simplified a little and added the ability to use the same functionality in file dialog popups, and the following seems to work well in everything I've tested so far.

Code: Select all

#IfWinActive, ahk_class #32770
~WheelDown:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
~WheelUp:: ;Explorer window - scroll pane under cursor (tested on Windows 7)

#IfWinActive, ahk_class CabinetWClass
~WheelDown:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
~WheelUp:: ;Explorer window - scroll pane under cursor (tested on Windows 7)

#IfWinActive, ahk_class ExploreWClass
~WheelDown:: ;Explorer window - scroll pane under cursor (tested on Windows 7)
~WheelUp:: ;Explorer window - scroll pane under cursor (tested on Windows 7)

ControlGetFocus, vCtlClassNN1, A
MouseGetPos,,,, vCtlClassNN2
if vCtlClassNN1 != vCtlClassNN2
	ControlFocus, % vCtlClassNN2, A

return
#IfWinActive
When the mouse moves to the other pane, the the wheel move still jars the originally focused pane and then the remaining wheel events move to the newly focused pane. It's a small price to pay to the improved functionality.

I do wonder, though, if there's a way to combine all the #IfWinActive since the wheel hotkeys are repeated for all of them.

Great job in figuring all that out!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Windows Explorer folder positions and scrolling

27 Jun 2017, 11:25

Ah yes, there is the jarring, I wondered if anyone would notice, that doesn't happen, if you consume the hotkey.

Re. repeating the hotkeys, I do this:

Code: Select all

GroupAdd, WinGroupExplorer, ahk_class CabinetWClass
GroupAdd, WinGroupExplorer, ahk_class ExploreWClass
GroupAdd, WinGroupExplorer, ahk_class Progman
GroupAdd, WinGroupExplorer, ahk_class WorkerW

GroupAdd, WinGroupFolder, ahk_class CabinetWClass
GroupAdd, WinGroupFolder, ahk_class ExploreWClass

GroupAdd, WinGroupDesktop, ahk_class Progman
GroupAdd, WinGroupDesktop, ahk_class WorkerW

#IfWinActive, ahk_group WinGroupExplorer
q::
MsgBox, % A_ThisHotkey
return
#IfWinActive
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
illuzioner
Posts: 27
Joined: 07 Jun 2017, 13:50

Re: Windows Explorer folder positions and scrolling

28 Jun 2017, 12:02

Ah, yes. GroupAdd. I had seen that command but didn't know what it was and didn't have time to investigate. Now that I know, I can see how it's very useful.

Thanks for sharing that!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 172 guests