Hold ESC down for about two seconds, and you're out of most windows and browser tabs. This script notices the difference between being in and out of a browser; within, tabs are closed, not the browser itself. Other than that, it doesn't differentiate.

~*$ESC::
settimer, click, -100 ; 0.10 seconds (?)
WinGetTitle, Title, A
KeyDown:=A_TickCount
Keywait Esc
if (A_TickCount-KeyDown > 650)
{
If title contains Internet Explorer, Nightly, Aurora, Firefox, Google Chrome, Opera
send, ^w
Else
winclose, %title%
}
Else
{
send, {ESC}
settimer,click, off
}

Click:
return