After experimenting I see that my script doesn't take account of minimized windows, which is a main reason to use AltTab in the first place.. Duh!!
So now I get the window position and if either the x or y is < 0 then it's minimized, so I wait a short number of loops with a 1/10th second sleep for the window to open, then put the mouse cursor near the origin. Here's the revised section of code:
~!Tab::
KeyWait, Alt
KeyWait, Tab
WinGetPos,x,y,width,height,A
While (x < 0 Or y < 0)
{
Sleep,100
WinGetPos,x,y,width,height,A
IfGreater,A_Index,2,Break
}
MouseMove,16,16
return
The rest of the code just does Tray menu stuff.
A compiled version is on my
hotkeys page.