Create A Shortcut Key For Restoring A Specific Window

Windows only: If you've ever wanted to assign a shortcut key directly to your favourite applications, you can do so easily with this simple AutoHotkey script.

The general idea of the function is that you can assign a specific hotkey to a specific window — when you press the shortcut key once, the window will come to the foreground, and if you press it again, the window will minimise. This way you can toggle between the windows you use most often, without having to bother with Alt-Tab.

To make your own AutoHotkey script for restoring a specific window, create a new *.ahk script and paste in the following code:

ToggleWinMinimize(TheWindowTitle)

{

SetTitleMatchMode,2

DetectHiddenWindows, Off

IfWinActive, %TheWindowTitle%

{

WinMinimize, %TheWindowTitle%

}

Else

{

IfWinExist, %TheWindowTitle%

{

WinGet, winid, ID, %TheWindowTitle%

DllCall("SwitchToThisWindow", "UInt", winid, "UInt", 1)

}

}

Return

}

Now that you have the function, you can start using it to create your own hotkeys for specific applications with a line similar to this one, which would assign Alt+X to toggle Firefox between being minimised and active.

!x::ToggleWinMinimize("Mozilla Firefox")

This script is courtesy of the Lifehacker Coders group over on Productive Geek forums, and reader bobbo33 is the AutoHotkey wizard that figured out how to make it work for any window, and solved a long-standing problem I've personally had with the WinRestore function. Thanks, bobbo33!

Use AutoHotkey to Assign a Hotkey to a Specific Window [Productive Geek]


Comments

    For me the script's only minimising the applications (outlook and putty). It doesn't want to restore the window.

    Is anyone else experiencing this?

    My history looks like this:
    002: ToggleWinMinimize("Outlook")
    008: SetTitleMatchMode,2
    009: DetectHiddenWindows,Off
    010: IfWinActive,%TheWindowTitle%
    016: IfWinExist,%TheWindowTitle%
    018: WinGet,winid,ID,%TheWindowTitle%
    019: DllCall(“SwitchToThisWindow”, “UInt”, winid, “UInt”, 1)
    020: }
    021: }
    022: Return

    This ToggleWinMinimize would be of awesome help to reduce unnecessary mouse movements or Alt-tabbing! I experience the same problem for Win7, minimizing works, but not restoring.
    Thanks a lot!

    ToggleWinMinimize(TheWindowTitle)
    {
    SetTitleMatchMode,2
    DetectHiddenWindows, On
    IfWinActive, %TheWindowTitle%
    {
    WinMinimize, %TheWindowTitle%
    }
    Else
    {
    IfWinExist, %TheWindowTitle%
    {
    WinGet, winid, ID, %TheWindowTitle%
    DllCall(“SwitchToThisWindow”, “UInt”, winid, “UInt”, 1)
    }
    }
    Return
    }
    #q::ToggleWinMinimize("Firefox")

Join the discussion!

Trending Stories Right Now