5

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?

Ola
  • 629
  • 1
  • 8
  • 18

3 Answers3

16

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
Syscall
  • 19,327
  • 10
  • 37
  • 52
Nathan
  • 1,675
  • 17
  • 25
  • Does that work for you? It doesn't for me (in Win7) even though Window Spy tells me the same as you wrote. Or do I need to put in some wildcard as well? – Ola Dec 09 '10 at 18:12
  • It works for the following code: #IfWinActive ahk_class CabinetWClass #a:: Msgbox Yeah, it works! Maybe if you post the reset of your hotkey routine, there's something besides the hotkey that's causing problems? – Nathan Dec 09 '10 at 19:31
  • It worked. But I had remapped my l above to I had to write ^p::Send {F4} to match the l keycode. Thanks a lot for the help! – Ola Dec 09 '10 at 21:16
  • Same name for Windows 10: `CabinetWClass` – Avatar Oct 08 '19 at 05:33
4

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
Syscall
  • 19,327
  • 10
  • 37
  • 52
Jay G
  • 167
  • 1
  • 6
3

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.

Community
  • 1
  • 1
  • Unfortunately, the "Suggested edit queue is full". Maybe also some credit to [Jay G](https://stackoverflow.com/a/6627982/4575793)? – Cadoiz Jun 26 '21 at 15:30