Prevent Alt+Tab from switching to minimized windows
I have looked at various solutions to this but none worked.
How can I prevent Alt+Tab in Windows 10 from switching to minimized windows?
The solution is to use Alt+Esc
It'll switch to the next open window, skipping minimized ones. More importantly it works even if the Windows Shell hangs up and Alt+Tab stops working
Unfortunately, with all this excitement attached to Alt+Tab, another hotkey has been woefully neglected. Windows 2.0 introduced the Alt+Esc hotkey. Whereas Alt+Tab lets you pick an application, Alt+Esc lets you cycle through them.
When you press Alt+Esc, the active window is sent to the bottom of the window stack, allowing the window beneath it in the z-order to become the new active window. And if the next window is a minimized window, it stays minimized. While this may sound like an annoyance, it is actually a useful device, as it lets you skip past minimized applications without having to open them.
Raymond Chen Discusses the Alt+Tab and Alt+Esc Hotkeys
The following script for AutoHotkey v1.1 fixes this issue by detecting when any window is minimized, and forcing it toward the end of the alt-tab list by temporarily changing window styles. The script runs in the background and does not require using a specific hotkey (or any hotkey).
; Use a shell hook to detect minimize and fix the alt-tab order.
OnMessage(DllCall("RegisterWindowMessage", "str", "SHELLHOOK"), "ShellHook")
DllCall("RegisterShellHookWindow", "ptr", A_ScriptHwnd)
ShellHook(wParam, lParam)
{
if (wParam != 0x5) ; HSHELL_GETMINRECT
return
hwnd := NumGet(lParam+0)
WinGet minmax, MinMax, ahk_id %hwnd%
if (minmax = -1) ; Minimized
{
; Remove the window from the alt-tab list temporarily to force
; it to the end of the list. To do this, temporarily apply the
; WS_EX_TOOLWINDOW style and remove WS_EX_APPWINDOW (if present).
WinGet oldxs, ExStyle, ahk_id %hwnd%
newxs := (oldxs & ~0x40000) | 0x80
if (newxs != oldxs)
{
WinSet ExStyle, % newxs, ahk_id %hwnd%
WinSet ExStyle, % oldxs, ahk_id %hwnd%
}
}
}
Caveat: This may have adverse effects on some windows since it modifies the window's extended style attribute (temporarily). I did not observe any issues during my testing.
I found that temporarily removing the window from alt-tab moved it almost to the end of the list. If I minimize multiple windows in a row, the first one appears last, with each subsequent minimized window inserted before the others (but after all other windows).
I tested on Windows 10 v1709. Results may vary on other systems.
I agree with what @LưuVĩnhPhúc suggested, and I went ahead and wrote a short AutoHotkey script that does more or less that.
The Script
forward := true
cycling := false
~Alt Up::
if cycling
forward := !forward
cycling := false
return
!Tab::Cycle(forward)
!+Tab::Cycle(!forward)
Cycle(direction)
{
global cycling
if direction
{
send !{Escape}
}
else
{
send !+{Escape}
}
cycling := true
}
!Escape::!Tab
Install the program, put this in an .ahk
file somewhere and run it.
It will set Alt+Tab to use Alt+Escape and Alt+Shift+Escape alternatingly so you can switch back and forth. The last line makes it so that Alt+Escape functions as the regular Alt+Tab, in case you want to still have access to that functionality. You can remove it if you want.
Caveats
-
This script changes Alt+Tab to be either Alt+Escape or Alt+Shift+Escape, changing its direction whenever you release the Alt key after having switched windows (i.e. also pressed Tab) at least once.
This doesn't change the mechanism behind Alt+Escape, so if you hold Alt and press Tab twice, you may not get to the second-before-last window you were in. Also when the direction is "reversed" you may get "older" windows (windows you haven't used in a while) before you get recent ones, with the exception of the last window you switched to; you'll get that one (that's the whole reason I made that flip in direction in the first place).
Ctrl+Alt+Tab still retains its original function - i.e. it uses the regular Alt+Tab mechanism. No idea what you want to do about that.
More Complicated Alternative
Another option is to write a program that can hide all the currently minimized windows and restore them, then use AutoHotkey to make Alt+Tab activate that program to hide all the minimized windows before letting the Alt+Tab through, and then have it show them again when you release Alt after having switched windows (no need to do it if you press Alt for other reasons).
This requires more work, however, and it'll result in your open applications in the taskbar changing while you switch windows and reverting when you stop, which may look strange.
If you choose to do this, I suggest you take notice not to invoke the program simply on Alt+Tab, but only on the first time you press that combination since you've held down Alt.