Create The Perfect, Customised Boss Key With AutoHotkey

We've all been there — trying to do something else while we're supposed to be working for the man. Sure, they are paying us, but can't we get a little break every now and then?

There are dozens of "Boss Key" applications out there, that hide windows with a simple keystroke whenever the boss walks by, but most of them aren't tailored very well to your own situation, or just aren't customisable enough for my tastes — so I set about to create the perfect boss key with AutoHotkey.

Of course, We're not actually advocating that you slack off at work, trick your boss, or do anything that goes against your employer's policies and get you sent home with a pink slip.

Getting Started

Before you can get started creating your own awesome boss key, you'll need to make sure that you've got AutoHotkey installed somewhere, and you might want to check out our beginner's guide for a little background on how it all works. If your workplace doesn't allow you to install software, you can create your script on another computer.

Once you have your environment up and running, create a new AutoHotkey script from File –> New menu, and then paste in the following starter script:

#InstallKeybdHook #Persistent #HotkeyInterval,100 #NoEnv SetKeyDelay, –1 SetTitleMatchMode, 2 ; Makes matching the titles easier SendMode Input SetWorkingDir %A_ScriptDir%

Then you'll want to add the following two blocks to the file, which give you one hotkey to hide everything, and another for restoring them. For the purposes of this article, we'll use F6 to hide everything, and F7 to show the windows again, but I'd probably recommend making the hide key something easier to hit, and keep the show key further away.

F6:: { ; put the hiding windows stuff here Return }

F7:: { ; put the functions to show everything again here Return }

Now that we've got the template script together, let's customise our script and hide some windows.

Hide Windows or Just Minimise Them

Most of the point of using a boss key is to hide whatever you are looking at, but that doesn't always mean you need to completely hide the window — if nobody looks that closely at your open windows, or you keep your taskbar hidden, minimising might be fine. You can either use the WinHide or WinMinimize AHK functions depending on which action you want to take.

To minimise a window, you can use the WinMinimize function followed by a part of the window title. For example, to minimise your VLC window, you can add the following two lines into your function:

WinMinimize, VLC media player

The line is fairly self-explanatory-you are simply telling AutoHotkey to minimise the window that matches that title string. If you wanted to hide the window instead, you'd use:

WinHide, VLC media player

The problem with hiding windows is that they are really completely hidden, so you will be forced to create another hotkey to show the window again, or you'll have to kill the process from task manager.

To show the window again, the following to the show window block:

DetectHiddenWindows, On WinShow, VLC media player

The first line tells AHK to also check for windows that are hidden, and the second line tells Windows to unhide the window.

Pause Your Media Player

Depending on your media playing application, you might have a number of ways to trigger a pause — if you can assign a global hotkey like your keyboard's media pause key, you can simply add that key to your boss key using the Send function, which can send keystrokes to the active window.

Send, {Media_Play_Pause}

There's a whole list of special keys that you can use instead, but if your favourite media application has command line arguments, you can also use the Run function to launch the application instead.

Run, C:pathtomedia-app.exe /pause

Switch to "Work Application"

To complete the boss key hiding effect, you can't just hide the windows you shouldn't have sitting open — it works best when you also switch over to whatever work application you are supposed to be using. If you are a programmer, like yours truly, nobody can argue with you having your favourite IDE open on the screen.

Inside our "Show" function, we'll need to add a line that switches back to the window we want to have on the screen. To accomplish this, we'll use the WinActivate function, which makes another window the topmost one.

WinActivate, Visual Studio

This function works just like the other ones, matching part of the title string-so you can customise it for whatever your work-safe application is.

Wrapping Up: Prepare Your Script

Once your script is finished up, you can package the script up into a single executable file that you can drop on a flash drive — especially helpful if your workplace doesn't allow you to install AutoHotkey on the target machine. The first thing you'll probably want to do is tell AutoHotkey not to show a tray icon, and run completely in the background. You'll want to add the following near the beginning of the script — note that if you do want to kill the script after adding this line, you'll have to do so from task manager.


Now you can right-click on the script, and choose to Compile it into an executable file, which you can then save on a flash drive, or use anywhere you want.

Here's the full listing of the example script, which hides VLC when you press the F6 key, and shows it again when you press F7.

#InstallKeybdHook #Persistent #HotkeyInterval,100 #NoEnv SetKeyDelay, –1 SetTitleMatchMode, 2 ; Makes matching the titles easier SendMode Input SetWorkingDir %A_ScriptDir%

F6:: { ; put the hiding windows stuff here WinHide, VLC media player Return }

F7:: { ; put the functions to show everything again here DetectHiddenWindows, On WinShow, VLC media player Return }

Now that you've put together your own customised boss key, do you have any tips for the rest of the class? Tell us in the comments.


    Here's a boss key program that requires no configuration and scripting

    Excellent !

Join the discussion!

Trending Stories Right Now