AutoHotKey: #IfWinActive .* Explorer *. ? in windows 7
Asked Answered
D

3

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?

Detestable answered 9/12, 2010 at 17:44 Comment(3)
This question probably belongs to superuser.comFructiferous
Ah. I didn't know about that. Thanks. I'll ask my following questions there.Detestable
Related: superuser.com/q/1489874/169199Ollayos
E
17

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
Exeat answered 9/12, 2010 at 18:5 Comment(4)
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?Detestable
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?Exeat
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!Detestable
Same name for Windows 10: CabinetWClassOllayos
T
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
Traweek answered 8/7, 2011 at 17:14 Comment(0)
A
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.

Agrestic answered 15/5, 2019 at 22:35 Comment(1)
Unfortunately, the "Suggested edit queue is full". Maybe also some credit to Jay G?Lien

© 2022 - 2024 — McMap. All rights reserved.