When I’m typing, I’m too lazy to leave the keyboard and use the mouse, so I came up with a quick window operations method.
Implementing Alt+1 for Minimize/Restore the current window, +2 for Restore, and +3 for Maximize using AutoHotKey.
!1::
; If no window is already selected
; or the selected window doesn't exist anymore,
; select the currently active window and minimize it:
IfWinNotExist, ahk_id %selected_id%
{
If (IsWindow(WinExist("A")) || WinActive("ahk_class ArtRage 3"))
WinGet, selected_id, ID, A
else
{
MsgBox, No window selected
return
}
}
WinGet, WinState, MinMax, ahk_id %selected_id%
If WinState = -1 ; the selected window is minimized
{
WinRestore
selected_id := ""
}
else
WinMinimize
return
; This checks if a window is, in fact, a window,
; as opposed to the desktop or a menu, etc.
IsWindow(hwnd){
WinGet, s, Style, ahk_id %hwnd%
return s & 0xC00000 ? (s & 0x100 ? 0 : 1) : 0
}
!2::
WinRestore,A
return
!3::
WinMaximize,A
return
Code explanation
- !1::: This line defines a hotkey, where ! represents the Alt key, and 1 is the numeric key. So, pressing Alt + 1 triggers this hotkey.
- IfWinNotExist, ahk_id %selected_id%: This conditional statement checks if a window with the specified ID (selected_id) exists. If not, it selects the currently active window.
- Inside the conditional block:
- WinGet, selected_id, ID, A: Retrieves the ID of the currently active window and stores it in the variable selected_id.
- WinGet, WinState, MinMax, ahk_id %selected_id%: Retrieves the minimize/maximize state of the selected window.
- If WinState = -1: Checks if the selected window is minimized.
- If true, it restores the window with WinRestore and clears the selected_id.
- If false, it minimizes the window with WinMinimize.
- IsWindow(hwnd): This function checks if the specified window handle (hwnd) corresponds to an actual window (as opposed to the desktop or a menu). It examines the window style.
- !2:: WinRestore,A: Defines another hotkey (Alt + 2) to restore the active window.
- !3:: WinMaximize,A: Defines another hotkey (Alt + 3) to maximize the active window.
However, I always feel that these quick window operations are a bit cumbersome. If you have a better solution, feel free to leave a message and let me know.