SEARCH

How-To Geek

Use AutoHotkey to Assign a Hotkey to a Specific Window

[updated with solution]

I’ve got a function that toggles a window between being active and being minimized, so I can quickly access my favorite applications with a custom hotkey for each. I’ve been using this system for years, but I’ve started having more and more problems with regaining focus once the window is restored…

Thankfully bobbo33 solved the problem, so I’ve updated this post with the full, working function. This solves the issue of restoring a window using AutoHotkey when the focus doesn’t come with it – Google Chrome and Firefox being the major culprits.

Here’s my simple function:

ToggleWinMinimize(TheWindowTitle)
{
 SetTitleMatchMode,2
 DetectHiddenWindows, Off
 IfWinActive, %TheWindowTitle%
 {
   WinMinimize, %TheWindowTitle%
 }
 Else
 {
   IfWinExist, %TheWindowTitle%
   {
       WinGet, winid, ID, %TheWindowTitle%
       DllCall("SwitchToThisWindow", "UInt", winid, "UInt", 1)
   }
 }
 Return
}

You can use this function like this:

!x::ToggleWinMinimize("Mozilla Firefox")

This would then assign Alt+X to hide or minimize your Firefox window. Personally I use this to assign hotkeys to Google Chrome Application windows for each of my webapps, like Gmail.

  • Published 02/11/10

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!