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

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?

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

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.

Related

AutoHotkey script only works when this window is open

Autohotkey script only works when I have this window open (please see screenshot). If I minimise it, it does not work. I have the H visible in the tray. Any help would be appreciated, thanks.
My script to use with Windows Pen is simply:
#F20::Run OneNote ; Single click, Open OneNote
if your keyboard has a f20 key
#F20::Run C:\Windows\write.exe
Would run wordpad.
Supply the path where OneNote is located.
#F20::Run path\OneNote

Access the MDI toolbar menu with AutoHotKey ControlSend

Automating a process that is being run on a RDP session, I have to use ControlSend, and not Send command in AutoHotKey.
The WindowSpy doesn't find any control on the MDI toolbar, and there are no shortkey to the menu item I want to access (Filter..). How may I open the toolbar and select the item?
I've tried
ControlSend, ahk_parent, {alt}, ahk_class FNWND3170 ;Open project folder in treeview
But with no success.
I've considered using AutoIT, but I don't think that would help as the AutoIt spy doesn't pick up the control either.
Sorry, but think of the RDP window (or even full screen) as an ever-evolving bitmap image. Your PC and autohotkey have no idea what is behind the picture. Can you run the ahk script in the remote pc itself? Keep in mind, the RDP client handles your mouseclicks and keyboard (and even voice) entirely by re-directing inputs, etc. So best bet is to do a mouse click in the appropriate spot by running a script from outside the window:
CoordMode, TargetType [, RelativeTo]
Click, 44, 55 ; Clicks the left mouse button once at coordinates 44, 55 (based on CoordMode).
Use the CoordMode "RelativeTo" flag to set to "Relative" so coordinates are relative to the active window. You may have to click twice, once to activate the RDP window and then to click at the mouse position.
See https://www.autohotkey.com/docs/commands/Click.htm and https://www.autohotkey.com/docs/commands/CoordMode.htm for info.
Hth,

Make Shortcut key to work only if Windows Explorer is open in AHK

I have a requirement of opening my application using Ctrl + F within Windows Explorer. I think I can implement this using Auto hot key.
WinWait, Windows Explorer
{
^f::
Run "C:\myapp.exe"
return
}
But the code is not working. The code opens my application even if Windows Explorer is not open. I want Ctrl + F to be open my application only if it is active in front. I dont want to open my application even if Windows Explorer is minimized.
How can I achieve this ?
Is there any other techniques to achieve the same ?
The #IfWin directive creates context-sensitive hotkeys. Such hotkeys perform a different action depending on the type of window that is active or exists.
https://autohotkey.com/docs/commands/_IfWinActive.htm
#IfWinActive ahk_class CabinetWClass
^f::
Run "C:\myapp.exe"
return
#IfWinActive ; turn off context sensitivity
The class name of a window identifies what type of window it is.
https://autohotkey.com/docs/misc/WinTitle.htm#ahk_class

In notepad++ change tab size instantly

I'm using notepad++ (v6.5.3) and I constantly have to change the size of the tab for viewing some results. Not that it's taking me a lot of time to do it manually everytime, but it would be great if I could optimize that.
Is there a way to do so? Would a macro be the solution, or are they just for typing stuff?
Thanks a lot!
Ok, there's an easy way how you can achieve this - I have tested it right now:
Install AutoHotKey (or start portable version which runs without installation)
In Windows 7 and above, ensure you launched AutoHotKey as Administrator (otherwise you get inconsistencies in its behavior) - if not sure, exit it and restart it as administrator
Right click Autohotkey tray icon and select Edit This Script
Import the macro below this list at the end of the AutoHotKey script file and save the file
Right click Autohotkey tray icon and select Reload This Script.
–– This was end of general steps, now let's go with your macro: ––
In N++, display Preferences window and press its Close button1 at the bottom (NOT at the top-right corner)
Now you can use shortcuts Win+F2 and Win+F3 to switch different tab sizes instantly
SendMode Input
DetectHiddenWindows, On
SetTitleMatchMode, RegEx
;--------------------------------- Hotkeys for Notepad++ only
#IfWinActive ahk_class Notepad\+\+
#F2::Send {F10}{Right 6}{Down}{Enter}{Tab 2}{Space}16{Enter}{Tab 3}{Space}
#F3::Send {F10}{Right 6}{Down}{Enter}{Tab 2}{Space}4{Enter}{Tab 3}{Space}
#IfWinActive
1) Important: N++ user experience provided in dialog boxes is absolutely terrible. There are no anchors where you can fix focus when using keyboard. Thus you always need to perform step 4 manually when leaving Preferences dialog box otherwise the macros would send keys into incorect window page OR at correct page but incorrect control. Preferences dialog window remembers selected page and control. Macros I created for you therefore assume that correct page is already listed and button Close was recently focused.
Good news is Notepad++ windows with this weird behavior are rare exception from general user experience. In other places in N++ (or in other apps) where user interface components (menus, dialogs etc.) always start from the same point you do not need any special precautions like the one in step 4.
Adjust the macros as you like:
you can create more of them
you can adjust the numbers "16" and "4" typed into tab size input box
you can change shortcut keys to something else
you can replace sending keys with sending mouse clicks at desired screen/window positions
you can achieve many other useful shortcuts in N++ and in all other apps – check AHK deeper!

Is there a keyboard shortcut to refresh project in eclipse?

I am looking for something other than right clicking on the project and then Refresh all option. Because its painful. I'm using an older version of Eclipse (v3.5).
It's not ideal, but 'Shift-Alt-Q, P' (do the shift-alt-q combination, release all of the keys and then press 'p') brings you to the package explorer, where if you hit F5 while your project is selected, will refresh that whole project.
Like I said, not ideal, but the best I've been able to come up with.
Doesn't F5 work?
CTRL+SHIFT+L should list the keyboard shortcuts available.
Again, I can't offer an ideal solution, but an option for Windows users that find this frustrating and want a 'minimal key press' solution.
I managed to write a script for AutoHotKey that will listen to the Win+F5 key when Eclipse is the active window. If it detects the Win+F5 key, it will automatically do Brian Gruber's technique: Shift-Alt-Q, P, (EDIT 20/02/2020: I added a press of the 'Home' key, to assure the top-most project node in the package explorer is selected), followed by F5, and then followed by F12, to bring focus back to the editor.
"eclipse_Win_F5_refresh.ahk"
#IfWinActive ahk_class SWT_Window0
; Win+F5 = Refresh Eclipse project
$#F5::
Send, !+q
Send, p
Send, Home
Send, {F5}
Send, {F12}
return
So then it's just a matter of:
Save the script to a file
Install AutoHotKey
Double-click the script file to run it
Press Win-key+F5 in eclipse to get your project refresh