Use AutoHotkey to Assign a Hotkey to a Specific Window

By Productive Geek on February 11th, 2010

[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:

 DetectHiddenWindows, Off
 IfWinActive, %TheWindowTitle%
   WinMinimize, %TheWindowTitle%
   IfWinExist, %TheWindowTitle%
       WinGet, winid, ID, %TheWindowTitle%
       DllCall("SwitchToThisWindow", "UInt", winid, "UInt", 1)

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
More Articles You Might Like

Enter Your Email Here to Get Access for Free:

Go check your email!