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

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

Related

Autohotkey Key for hiding current window

I try to close a window with the below configuration when pressing Ctrl and h.
Unfortunately it does not work.
E.g. in Chrome it opens the little window as if you press alt+space, when I focus the address bar in Chrome it works.
What do I do wrong?
;Hide a window
^h:: Send !{Space}n
Return
I managed to get a solution which fixes my issue:
I now use Kinto, which itself uses AutoHotkey, and it has the key action I want right from the start using the Mac OS Layout from the Kinto Installation Options.
Kinto itself uses AutoHotkey, you can find the AutoHotkey-file on Github.

Activate my app from the tray - AHK

Imagine my application's window class name is classAbc
My app has a minimized in tray ability,
When a custom key is pressed it goes into tray,
How to activate it from the tray?
WinActivate, ahk_class classAbc
won't work at that time
I also tried WinShow with no success
Will it have a different class name when it goes into tray?
if so I used a macro recorder to find it's class name when it is resident in tray
but just found 2 classes which I think both are related to Microsoft windows menubar itself:
The classes and the activation codes:
WinActivate, ahk_class Shell_TrayWnd
WinActivate, ahk_class NotifyIconOverflowWindow
Tried these also but my app doesn't appeared once it goes to the tray.
Thanks in advance for any help
There are two methods depending on how your application manages its minimizing to tray:
WinShow ahk_class YOUR_APP_WINDOW_CLASS - to get the main window class name use AHK's built-in Window Spy available from a tray menu of an AHK script or in Windows Start Menu.
If the above method stops working on subsequent runs then the application stores its minimization state internally and you'll have to use TrayIcons function to send a mouse click message to the tray icon.
Since the application that is in the tray is just hidden (usually), you should use DetectHiddenWindows first. Then you use WinActivate
So it will look like this
#NoEn ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
DetectHiddenWindows, On
WinActivate, ahk_class classAbc
PS. I don't know what you want to do after activating the app from tray, but it might be a good idea to use WinWaitActive before anything else

If statements in autohotkey

I would like a hotkey that opens Chrome when I hold the windows key and press "c". This is what I have written:
#c::Run chrome.exe
however, if chrome is already open, I would like it to activate that window instead. The example of such a script given in the beginner's tutorial is this
IfWinExist Untitled - Notepad
{
WinActivate
}
else
{
Run Notepad
WinWait Untitled - Notepad
WinActivate
}
Unfortunately, the name of any Chrome window is (current website) - Google Chrome so I need to know how to use some kind of universal name for my Chrome windows so that it will recognise them as the one program. Any help is appreciated. I am total noob
You can use the ahk_class of the window instead, it's like a unique identifier for the window. You can get it by right-clicking the autohotkey icon in your taskbar, selecting "Window Spy" then clicking on Chrome and copying the ahk_class.
if (WinExist("ahk_class Chrome_WidgetWin_1"))
WinActivate, % "ahk_id " WinExist("ahk_class Chrome_WidgetWin_1")
else {
MsgBox, Run Google Chrome
;Run, chrome.exe?
}

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

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?
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.