Windows – How to return focus to the previous window

autohotkeywindows 7

I have an Autohotkey script which opens and closes a pop-out command line similar to the Quake console dropdown. When I close it, however, it places focus on the taskbar. How can I instead return focus to the top window in the stack?

Best Answer

WinGet, ActiveId, ID, A
WinWaitNotActive, ahk_id %ActiveId%
WinActivate, ahk_id %ActiveId%