Step 3Configure your Hotkey Mapper, part 2.
Let's try again:
#`::IfWinExist ahk_class Console Main Command Window{ IfWinActive ahk_class Console Main Command Window { WinHide ahk_class Console Main Command Window } else { WinShow ahk_class Console Main Command Window }}else Run [[shortcut to console]]returnOkay; that should work, right?
Not quite. It's good, but it's not right. Yet. We have a couple of issues outstanding.
When you run the script, and press your hotkey, you'll notice that Console launches. Another press - it disappears. Great!
Not really. Press it again - and it launches another session of Console! That's not right, is it?
Issue 1: Hidden Consoles stay hidden
So, we're losing the script at "IfWinActive" - it can't find the hidden Console!
AHK has a command for that - DetectHiddenWindows. Let's add it now.
#`::DetectHiddenWindows, onIfWinExist ahk_class Console Main Command Window{ IfWinActive ahk_class Console Main Command Window { WinHide ahk_class Console Main Command Window } else { WinShow ahk_class Console Main Command Window }}else Run consoleDetectHiddenWindows, offreturnRun it again. This time, it'll hide - but, hmm... it won't come back!
Issue 2: Hidden Consoles really stay hidden
What's happening here is, the console is hidden by WinHide, but it's still active. We need to move the focus somewhere else, so that the IsWinActive call won't return true. The easiest place to send that focus is to the Windows Taskbar.
#`::DetectHiddenWindows, onIfWinExist ahk_class Console Main Command Window{ IfWinActive ahk_class Console Main Command Window { WinHide ahk_class Console Main Command Window WinActivate ahk_class Shell_TrayWnd } else { WinShow ahk_class Console Main Command Window }}else Run consoleDetectHiddenWindows, offreturnClose, but no cigar! It comes back, but it's not active - you can't just start typing!
Issue 3: Home movie effect - Console hasn't got focus!
Easy. We'll just make sure that when we show it, we give it focus straight away.
#`::DetectHiddenWindows, onIfWinExist ahk_class Console Main Command Window{ IfWinActive ahk_class Console Main Command Window { WinHide ahk_class Console Main Command Window WinActivate ahk_class Shell_TrayWnd } else { WinShow ahk_class Console Main Command Window WinActivate ahk_class Console Main Command Window }}else Run consoleDetectHiddenWindows, offreturnIt works! Except... we can't close it with escape. That's the icing on the cake.
Issue 4: No way out!
This is just a matter of adding a quick second script to the end of your .AHK file:
#IfWinActive ahk_class Console Main Command Windowesc:: { WinHide ahk_class Console Main Command Window WinActivate ahk_class Shell_TrayWnd }returnSimply: if we're in Console, escape hides it. Done!
So - that's it for the AHK file. But your console window is still appearing in the middle of the screen - not very Quake-like. Let's fix that.
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|







































