Wanted: Script that opens new explorer window when middle clicked
Wanted: Script that opens new explorer window when middle clicked
I really like the "middle click to open new tab" feature of web browsers. I'd like to get that functionality into Windows Explorer. It can be done with the keyboard with the context menu button and e. Is there a way I can make a script to activate those buttons in close succession on a middle click in Explorer only? I'm new to this and the documentation is a bit overwhelming, so I'd appreciate any help.
Re: Wanted: Script that opens new explorer window when middle clicked
From top to bottom (as the script will be written):
Seems effective on my Windows 10 system.
One drawback is that if you middle-click anywhere that isn't a folder (but is still within or part of an Explorer window), you might be surprised by what happens. This is what I observed:
- "on a middle click in Explorer only": Example 1 for #If shows how to make a hotkey sensitive to what kind of window the mouse is pointing at.
- "in Explorer only": You need to identify Explorer windows.
For any command that has a WinTitle parameter, you can pass ahk_class CabinetWClass to identify an Explorer window regardless of its title. (However, on Windows XP it can also be ExploreWClass.) You can find this information with Window Spy, which you can launch from the Start menu or the right-click menu of a running script's tray icon. - "on a middle click": Detect middle click with a simple hotkey: MButton::
- "activate those buttons in close succession": Use Send to "activate buttons". Specifically, Send {AppsKey}e will send the context menu button followed by e. In this case, you'll probably need to precede it with a click (Click, Send {Click} or Send {LButton}) so that the item you're pointing at gets selected.
Code: Select all
MouseIsOver(WinTitle) {
MouseGetPos,,, Win
return WinExist(WinTitle . " ahk_id " . Win)
}
#If MouseIsOver("ahk_class CabinetWClass")
MButton::
Send {LButton}{AppsKey}e
return
One drawback is that if you middle-click anywhere that isn't a folder (but is still within or part of an Explorer window), you might be surprised by what happens. This is what I observed:
- A folder on the side bar -> opens in the current window and a new window.
- Elsewhere on the side bar -> opens a new window for whichever folder was highlighted in the side bar.
- Inside the folder but not on an item -> refreshes the current window.
- On the window frame or scroll bars -> depends on what was highlighted.
- On an AutoHotkey script -> edits the script.
- Almost_there
- Posts: 404
- Joined: 30 Sep 2014, 10:32
Re: Wanted: Script that opens new explorer window when middle clicked
Then I suggest that middle click also engages ImageSearch and compare to a folder icon. Or there may be several variants on how the folder icon looks like...
Re: Wanted: Script that opens new explorer window when middle clicked
Hey, thanks! That's exactly what I wanted (even the explanation, but BOY does that not seem to simplify things... I'm glad this forum exists so I can keep asking questions...)
In the future when I get more scripts, is there a way to consolidate them all into one tray icon that summarizes them all so I don't have 20 icons down there?
In the future when I get more scripts, is there a way to consolidate them all into one tray icon that summarizes them all so I don't have 20 icons down there?
Re: Wanted: Script that opens new explorer window when middle clicked
Copy and paste?
You can use #Include if you want to keep them in separate files. Just use #Include wherever you would want to "paste" another file within this file.
Either way, the main thing to watch out for is that some scripts (but not this one) have code that needs to run immediately when you start the script. That code needs to go in the auto-execute section, or be called from there. The auto-execute section normally ends at the first hotkey, even if that's inside an included file.
There are also some directives, such as #If and #IfWinActive, which affect all hotkeys below that point. An #If in an included file may also affect lines after the #include in the main file. You can write the hotkey like this to avoid that problem:
You can also use something like AHKControl, but merging the scripts is better.
You can use #Include if you want to keep them in separate files. Just use #Include wherever you would want to "paste" another file within this file.
Either way, the main thing to watch out for is that some scripts (but not this one) have code that needs to run immediately when you start the script. That code needs to go in the auto-execute section, or be called from there. The auto-execute section normally ends at the first hotkey, even if that's inside an included file.
There are also some directives, such as #If and #IfWinActive, which affect all hotkeys below that point. An #If in an included file may also affect lines after the #include in the main file. You can write the hotkey like this to avoid that problem:
Code: Select all
#If MouseIsOver("ahk_class CabinetWClass")
MButton::
Send {LButton}{AppsKey}e
return
#If ; Reset hotkey criteria to 'none' - i.e. global.
- Almost_there
- Posts: 404
- Joined: 30 Sep 2014, 10:32
Re: Wanted: Script that opens new explorer window when middle clicked
I just throw out another way to somehow keep track of large files.
I always use Notepad2-mod to edit .ahk files, and I use the bookmark function actively.
That is Ctrl+F2 to toggle bookmark (at a line), F2 goto next bookmarked line and Shift+F2 goes to previous.
However for very large files, I too recomend using multiple .ahk files.
I always use Notepad2-mod to edit .ahk files, and I use the bookmark function actively.
That is Ctrl+F2 to toggle bookmark (at a line), F2 goto next bookmarked line and Shift+F2 goes to previous.
However for very large files, I too recomend using multiple .ahk files.
Re: Wanted: Script that opens new explorer window when middle clicked
How about this
Code: Select all
GroupAdd,Explorer,ahk_class ExploreWClass
GroupAdd,Explorer,ahk_class CabinetWClass
#IfWinActive,ahk_group Explorer
MButton::
Keywait,MButton
MouseGetPos,,,,Control
If Control = SysListView321
{
Click
for window in ComObjCreate("Shell.Application").Windows
{
Selected := window.Document.SelectedItems
Focused := window.Document.FocusedItem.Path
for item in Selected
Selected := item.path
Break
}
If Selected =
{
SplitPath,Focused,,Selected
Run,% Selected
}
Else
{
Dir := FileExist(Selected)
If Dir contains D
Run,% Selected
}
}
Return
-
- Posts: 1
- Joined: 22 May 2020, 13:39
Re: Wanted: Script that opens new explorer window when middle clicked
This script doesn't seem to work for me. Unfortunately, I don't yet know enough about AutoHotkey scripts to figure out exactly why it doesn't work. Has something changed in ahk in the last 4.5 years to break it?vsub wrote: ↑22 Oct 2015, 07:26How about thisCode: Select all
GroupAdd,Explorer,ahk_class ExploreWClass GroupAdd,Explorer,ahk_class CabinetWClass #IfWinActive,ahk_group Explorer MButton:: Keywait,MButton MouseGetPos,,,,Control If Control = SysListView321 { Click for window in ComObjCreate("Shell.Application").Windows { Selected := window.Document.SelectedItems Focused := window.Document.FocusedItem.Path for item in Selected Selected := item.path Break } If Selected = { SplitPath,Focused,,Selected Run,% Selected } Else { Dir := FileExist(Selected) If Dir contains D Run,% Selected } } Return
- tobsto occupied
- Posts: 186
- Joined: 20 Feb 2020, 09:34
- Contact:
Re: Wanted: Script that opens new explorer window when middle clicked
ditto...tried the most recent script from
vsub ...that one dont work , would appreciate it updated to work , first script at top has issues mentioned of opening a shortly visible right click menu and also the issue of not just opening folders but also opening folders when right clicking other stuff like the preview window etc
vsub ...that one dont work , would appreciate it updated to work , first script at top has issues mentioned of opening a shortly visible right click menu and also the issue of not just opening folders but also opening folders when right clicking other stuff like the preview window etc
- tobsto occupied
- Posts: 186
- Joined: 20 Feb 2020, 09:34
- Contact:
Re: Wanted: Script that opens new explorer window when middle clicked
would really appreciate it thanks
Re: Wanted: Script that opens new explorer window when middle clicked
Try:or
Code: Select all
MButton:: Run explorer
Code: Select all
MButton:: Send #e
- tobsto occupied
- Posts: 186
- Joined: 20 Feb 2020, 09:34
- Contact:
Re: Wanted: Script that opens new explorer window when middle clicked
Code: Select all
GroupAdd,Explorer,ahk_class ExploreWClass
GroupAdd,Explorer,ahk_class CabinetWClass
#IfWinActive,ahk_group Explorer
MButton::
Keywait,MButton
MouseGetPos,,,,Control
If Control = SysListView321
{
Click
for window in ComObjCreate("Shell.Application").Windows
{
Selected := window.Document.SelectedItems
Focused := window.Document.FocusedItem.Path
for item in Selected
Selected := item.path
Break
}
If Selected =
{
SplitPath,Focused,,Selected
Run,% Selected
}
Else
{
Dir := FileExist(Selected)
If Dir contains D
Run,% Selected
}
}
Return
where would that go into above code...im confuse a bit...the usual lol
- tobsto occupied
- Posts: 186
- Joined: 20 Feb 2020, 09:34
- Contact:
Re: Wanted: Script that opens new explorer window when middle clicked
uhhhhh both wont open the folder i click on ...but instead just opens up a generic explorer window now
-
- Posts: 4326
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Wanted: Script that opens new explorer window when middle clicked
Code: Select all
#If ExplorerUnderMouse()
MButton::
OpenFolderInNewWinow() {
Click
selected := Explorer_GetSelection()
if InStr( FileExist(selected), "D" )
Run, %selected%
else if SubStr(selected, -3) = ".lnk" {
FileGetShortcut, % selected, target
if InStr( FileExist(target), "D" )
Run, %target%
}
}
ExplorerUnderMouse() {
MouseGetPos,,, hWnd
WinGetClass, winClass, ahk_id %hWnd%
Return winClass ~= "^(Progman|WorkerW|(Cabinet|Explore)WClass)$"
}
Explorer_GetSelection() {
WinGetClass, winClass, % "ahk_id" . hWnd := WinExist("A")
if !(winClass ~= "^(Progman|WorkerW|(Cabinet|Explore)WClass)$")
Return
shellWindows := ComObjCreate("Shell.Application").Windows
if (winClass ~= "Progman|WorkerW") ; IShellWindows::Item: https://goo.gl/ihW9Gm
; IShellFolderViewDual: https://goo.gl/gnntq3
shellFolderView := shellWindows.Item( ComObject(VT_UI4 := 0x13, SWC_DESKTOP := 0x8) ).Document
else {
for window in shellWindows ; ShellFolderView object: https://is.gd/eyZ4zG
if (hWnd = window.HWND) && (shellFolderView := window.Document)
break
}
for item in shellFolderView.SelectedItems
result .= (result = "" ? "" : "`n") . item.Path
Return result
}
Last edited by teadrinker on 27 Jun 2021, 14:52, edited 2 times in total.
- tobsto occupied
- Posts: 186
- Joined: 20 Feb 2020, 09:34
- Contact:
Re: Wanted: Script that opens new explorer window when middle clicked
---------------------------
Mouse Middle Click to open folder while in Windows Explorer.ahk
---------------------------
Error at line 23.
The following variable name contains an illegal character:
"$""
The program will exit.
---------------------------
OK
---------------------------
Mouse Middle Click to open folder while in Windows Explorer.ahk
---------------------------
Error at line 23.
The following variable name contains an illegal character:
"$""
The program will exit.
---------------------------
OK
---------------------------
Code: Select all
#If ExplorerUnderMouse()
MButton::
OpenFolderInNewWinow() {
Click
selected := Explorer_GetSelection()
if InStr( FileExist(selected), "D" )
Run, explorer.exe "%selected%"
else if SubStr(selected, -3) = ".lnk" {
FileGetShortcut, % selected, target
if InStr( FileExist(target), "D" )
Run, explorer.exe "%target%"
}
}
ExplorerUnderMouse() {
MouseGetPos,,, hWnd
WinGetClass, winClass, ahk_id %hWnd%
Return winClass ~= "^(Progman|WorkerW|(Cabinet|Explore)WClass)$"
}
Explorer_GetSelection() {
WinGetClass, winClass, % "ahk_id" . hWnd := WinExist("A")
if !(winClass ~= ^(Progman|WorkerW|(Cabinet|Explore)WClass)$")
Return
shellWindows := ComObjCreate("Shell.Application").Windows
if (winClass ~= "Progman|WorkerW") ; IShellWindows::Item: https://goo.gl/ihW9Gm
; IShellFolderViewDual: https://goo.gl/gnntq3
shellFolderView := shellWindows.Item( ComObject(VT_UI4 := 0x13, SWC_DESKTOP := 0x8) ).Document
else {
for window in shellWindows ; ShellFolderView object: https://is.gd/eyZ4zG
if (hWnd = window.HWND) && (shellFolderView := window.Document)
break
}
for item in shellFolderView.SelectedItems
result .= (result = "" ? "" : "`n") . item.Path
Return result
}
-
- Posts: 4326
- Joined: 29 Mar 2015, 09:41
- Contact:
- tobsto occupied
- Posts: 186
- Joined: 20 Feb 2020, 09:34
- Contact:
Re: Wanted: Script that opens new explorer window when middle clicked
---------------------------
Mouse Middle Click to open folder while in Windows Explorer.ahk
---------------------------
Error at line 1.
Line Text: ##If ExplorerUnderMouse()
Error: This line does not contain a recognized action.
The program will exit.
---------------------------
OK
---------------------------
Mouse Middle Click to open folder while in Windows Explorer.ahk
---------------------------
Error at line 1.
Line Text: ##If ExplorerUnderMouse()
Error: This line does not contain a recognized action.
The program will exit.
---------------------------
OK
---------------------------
-
- Posts: 4326
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Wanted: Script that opens new explorer window when middle clicked
There is no such line in my code.
- tobsto occupied
- Posts: 186
- Joined: 20 Feb 2020, 09:34
- Contact:
Re: Wanted: Script that opens new explorer window when middle clicked
ok had one # too many at the very beginning of code
BUT....its alot slower than the first code that shows the right click menu tho , literally has a 2 second delay vs instantly
it seems to unlike the first code that opens within the same explorer process , it creates an entire new explorer process...this seems to be the issue here , meaning every opened folder would create a additional explorer.exe process aka not good
maybe if Vsubs code could be made to work , that would be the proper solution
BUT....its alot slower than the first code that shows the right click menu tho , literally has a 2 second delay vs instantly
it seems to unlike the first code that opens within the same explorer process , it creates an entire new explorer process...this seems to be the issue here , meaning every opened folder would create a additional explorer.exe process aka not good
maybe if Vsubs code could be made to work , that would be the proper solution
Code: Select all
GroupAdd,Explorer,ahk_class ExploreWClass
GroupAdd,Explorer,ahk_class CabinetWClass
#IfWinActive,ahk_group Explorer
MButton::
Keywait,MButton
MouseGetPos,,,,Control
If Control = SysListView321
{
Click
for window in ComObjCreate("Shell.Application").Windows
{
Selected := window.Document.SelectedItems
Focused := window.Document.FocusedItem.Path
for item in Selected
Selected := item.path
Break
}
If Selected =
{
SplitPath,Focused,,Selected
Run,% Selected
}
Else
{
Dir := FileExist(Selected)
If Dir contains D
Run,% Selected
}
}
Return
-
- Posts: 4326
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Wanted: Script that opens new explorer window when middle clicked
Replace Run, explorer.exe "%selected%" with Run, %selected% and Run, explorer.exe "%target%" with Run, %target%.tobsto occupied wrote: ↑every opened folder would create a additional explorer.exe process aka not good
Who is online
Users browsing this forum: doodles333 and 320 guests