- Press E to edit the selected file(s).
- Press D to recycle or delete the selected file(s).
Spoiler
In the current version (build 22000.613), most shortcut keys that would work in the classic menu (which can be shown by selecting "Show more options") do not work in the modern menu. I am used to right clicking and pressing "e" to edit a script, or "d" to delete a file, and do not particularly want to change these habits.
The solution has two parts:
- Detect when a hotkey is pressed while a File Explorer context menu is open.
- Find the selected item.
When a context menu is open, the Explorer window is active, not the context menu. The context menu can be detected with WinExist, so this combination of conditions will work:
Code: Select all
#HotIf WinActive("ahk_class CabinetWClass") && WinExist("PopupHost ahk_class Xaml_WindowedPopupClass")
To invoke other actions, we need to know which file is selected, as shown below:
Code: Select all
e::{ ; Press E to edit the selected files.
hwnd := WinExist("A")
for window in ComObject("Shell.Application").Windows
if window.HWND = hwnd
for item in window.Document.SelectedItems
item.InvokeVerb "edit"
; Run 'edit "' item.Path '"'
}
Spoiler
There is no requirement for the invoked verb to actually appear in the new Windows 11 menu, and of course, the script can do whatever it wants once it has the file path.
Altogether, with more reusable code:
Code: Select all
#Requires AutoHotkey v2.0-beta.3
#HotIf WinActive("ahk_class CabinetWClass")
&& WinExist("PopupHost ahk_class Xaml_WindowedPopupClass")
e::ForEachSelectedFile(item => item.InvokeVerb("edit"))
d::ForEachSelectedFile(item => item.InvokeVerb("delete"))
+d::Send("{Esc}"), WinWaitClose(,, 1) && Send("+{Delete}")
ForEachSelectedFile(action) {
if WinExist("PopupHost ahk_class Xaml_WindowedPopupClass")
Send "{Esc}"
hwnd := WinExist("A")
for window in ComObject("Shell.Application").Windows
if window.HWND = hwnd
for item in window.Document.SelectedItems
action(item)
}
Known issue: If you right click an item in the navigation pane/sidebar, the script will think you have right clicked an item in the main pane.