Win10资源管理器中AutoHotkey的!d::Send, {delete}脚本失效问题
Let’s break down exactly why this is happening, and how to fix it:
Core Reason
In Windows 10’s File Explorer, Alt+d is a native system-level shortcut hardwired to jump directly to the address bar. This system shortcut has higher priority than AutoHotKey’s standard hotkeys—so when you press Alt+d in File Explorer, Windows intercepts the keystroke first and runs its built-in function, leaving your AHK script never getting a chance to execute.
That’s why your script works everywhere else: most other apps don’t have a native Alt+d shortcut, so AHK can catch the keystroke and run your Send {Delete} command without conflict.
Fixes to Make the Script Work in File Explorer
Here are two reliable solutions tailored for this scenario:
1. Target File Explorer Explicitly with Window-Specific Hotkeys
Use AHK’s #IfWinActive directive to create a hotkey that only applies when File Explorer is active. This bypasses the system’s global shortcut handling for that specific window:
; Define the hotkey only for File Explorer windows #IfWinActive ahk_class CabinetWClass !d::SendInput {Delete} ; Reset hotkey scope to all windows #IfWinActive
ahk_class CabinetWClass: This is the window class name for Windows 10 File Explorer. You can verify this using AHK’s built-in Window Spy tool (right-click the AHK tray icon > Window Spy).SendInput: This sends keystrokes at a lower level than the standardSend, making it more likely to override the native shortcut in system apps like File Explorer.
2. Global Hotkey with Conflict Prevention
If you want the same Alt+d behavior across all apps (including File Explorer), use the $ prefix to prevent hotkey loops and ensure AHK catches the keystroke before the system does:
$!d:: ; Check if File Explorer is active IfWinActive ahk_class CabinetWClass { ; Send Delete and block the native Alt+d action SendInput {Delete} return } ; For all other apps, just send Delete SendInput {Delete} return
Quick Verification Tip
To confirm the window class is correct, open Window Spy, click on a File Explorer window, and look for the ahk_class field—it should show CabinetWClass for Windows 10.
内容的提问来源于stack exchange,提问作者aj3423

