Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
add a final ALT+Tab ? – Olivier Dulac Jan 7 '13 at 17:19
@OlivierDulac I tried that, that takes it to the second window in the stack. I suppose I could do two alt-tabs, but that's an ugly kludge. – SaintWacko Jan 7 '13 at 17:20

Instead of alttab, use shiftalttab. That return you to the previous focus program, instead of the next.

share|improve this answer
That takes me to the bottom window in the stack. – SaintWacko Jan 7 '13 at 18:40
Then try alt-tab, then shift-alt-tab. But seems it will be faster to use just the mouse to click the program on the task bar. – John Siu Jan 7 '13 at 18:43
Exactly why I'm looking for something to put in the AHK script to return focus to it. – SaintWacko Jan 7 '13 at 18:44
In your AHK script, can you use WinGetActiveTitle to get the active window before opening the pop-up, then use WinActivate to switch back after? – John Siu Jan 7 '13 at 18:49
WinGet, ActiveId, ID, A
WinWaitNotActive, ahk_id %ActiveId%
WinActivate, ahk_id %ActiveId%
share|improve this answer
The only problem with this is that my console window is set to stay on top, and is semi-transparent, so I can still work on other windows while it is up. Because of this, the window that is on top of the stack when I finish with the console may not be the same window that was active when I opened it. – SaintWacko Jan 7 '13 at 18:54
I'm hoping for a way to access the Windows API and get the ID of the window on top of the stack. – SaintWacko Jan 7 '13 at 18:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .