Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoHotKey: #IfWinActive .* Explorer *. ? in windows 7

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?

like image 227
Ola Avatar asked Dec 09 '10 17:12

Ola


People also ask

What do you use AutoHotkey for?

AutoHotkey scripts can be used to launch programs, open documents, and emulate keystrokes or mouse clicks and movements. AutoHotkey scripts can also assign, retrieve, and manipulate variables, run loops and manipulate windows, files, and folders.

Is AutoHotkey a malware?

AutoHotkey, an open-source scripting language for Windows, used for form fillers, auto-clicking, macros, etc. has been the target of multiple malware attacks. On its own, AutoHotkey isn't dangerous or malicious, it relies completely on scripts to perform actions.

Is AutoHotkey any good?

AutoHotkey is one of the best Windows automation programs that can perform the simplest of actions to the hardest of tasks. AutoHotkey is a free and open-source program which uses its own scripting language to automate any of your daily Windows tasks.

Is AutoHotkey secure?

Cybersecurity researchers have uncovered an ongoing malware campaign that heavily relies on AutoHotkey (AHK) scripting language to deliver multiple remote access trojans (RAT) such as Revenge RAT, LimeRAT, AsyncRAT, Houdini, and Vjw0rm on target Windows systems.


3 Answers

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
like image 70
Nathan Avatar answered Oct 31 '22 15:10

Nathan


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
like image 30
Jay G Avatar answered Oct 31 '22 15:10

Jay G


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.

like image 44
Mary Conseca Avatar answered Oct 31 '22 16:10

Mary Conseca