Question

I'm trying to make an AutoHotKey macro that's active only in Windows Explorer but I don't know the name of Explorer in Windows 7. I tried the following:

;Make explorer understand that Ctrl+L means goto location bar (like Firefox / Chrome)
#IfWinActive .* Explorer *.
    ^l::Send {F4}
#IfWinActive

Any ideas?

Was it helpful?

Solution

Autohotkey comes with a program called Window Spy. You can use it to discover the title of the active window.

Also, take note of ahk_class (look up ahk_class in the help file), which uses the type of window, rather than the title. For example, in my Win 7 case, I can restrict hotkeys to explorer by specifying:

#IfWinActive ahk_class CabinetWClass

OTHER TIPS

Windows Explorer seems to use different window classes at different times (e.g., if Search is displaying or not--at least in Win XP). This script matches the two classes I've seen and maps Ctrl-L to "focus on address bar" (ala Firefox) in Explorer:

#IfWinActive ahk_class ExploreWClass
^L::
#IfWinActive ahk_class CabinetWClass
^L::
    Send {F6}
return
#IfWinActive

Just wanted to thank Nathan enormously for resolving my problem -- virtually identical to Ola's question here. Had been using the very popular AHK script called "Favorite_folders" which displays a folders menu on Middle-button click. Been using for years in XP no problem -- but could not get the script to work in Win7 in a "Windows Explorer" window.

The script worked in all programs' explorer windows -- but NOT in a plain "Windows Explorer" window (as in -- Start > right-click > Open Windows Explorer). Spent over 20 hours trying to solve.

Nathan's advice to use the "#IfWinActive ahk_class CabinetWClass" script solved my problem. It led me to add the following script to the "Favorite_folders" script --

IfWinActive ahk_class CabinetWClass

f_AlwaysShowMenu = y

Apparently, the CabinetWClass refers to the "Windows Explorer" window -- whereas the ExploreWClass refers to the explorer window that appears in various programs when opening or saving a file. I needed the menu for both situations.

In the original "Favorite_folders" script, the command line for permitting a "f_Hotkey = ~MButton" menu to appear reads -- "if f_class in #32770,ExploreWClass,CabinetWClass ; Dialog or Explorer". For unknown reasons, this only permits the menu to appear in programs' explorer window -- but NOT a normal "Windows Explorer" window.

By adding the two command lines above to the original "Favorite_folders" script I was able to get the menu to appear in normal "Windows Explorer" windows -- but NOT in programs' explorer windows -- same problem in reverse. And if I added a second similar script modification for "#IfWinActive ahk_class ExploreWClass" -- then no menu appeared in either kind of explorer window. Crazy stuff -- by my reckoning.

So the solution for me was to load two separate versions of the "Favorite_folders" AHK script -- 1) the unmodified original Favorite_folders script; 2) a separate modified original Favorite_folders script with the two-line "#IfWinActive ahk_class CabinetWClass" command inspired by Nathan inserted into it. NOW -- the menu appears in both kinds of explorer windows. Not clear WHY these scripts cannot appear in a single script -- but they work just fine as separate scripts.

So a HUGE thanx to Nathan and Ola for raising and solving this issue and my problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top