Saving time with a keyboard macro layer

Switching apps is repetitive and time consuming, how can we simplify it to save time?

TLDR, if you already know AHK, here is the GitLab repo with the code to run

When working with a computer on research and development projects, one of the most common situations will be to find ourselves in having a wide selection of active apps.

This is a situation that plunges work efficiency and increases dead times mainly due to application switching and treasure hunts to find our windows.

Therefore, it is clear that we want to either avoid having many apps opened up in the first place or to speed the switching process up.

In this article, we’re going to talk about the latter, how to speed up application switching.

One of the great tools we have at our disposal is in front of us: the keyboard. With it, we can do more than typing single letters. We can also issue shortcuts like CTRL+X, CTRL+V, WINDOWS+TAB, etc, that will execute predetermined actions on the fly, without the need to move our pointer at all.

To execute more complex actions though, we might require a little help. This help comes in the form of a program called AutoHotKey.

AutoHotKey is a scripting language that enables us to perform certain actions when a specific event happens, in our case, when a key is pressed (but can be anything).

To make it work we just need to download the AutoHotKey (AHK) interpreter from the website, write our script on a notepad, rename the extension to be .ahk, and launch it.

Note: (the AHK website provides plenty of guidance for any use case (linux, windows, etc.) therefore I will not write the same installation and startup guide here as the user requirement scenario is quite vast and the work already is done on the AHK help site).

The next code section shows an example of the scripting language. Here we respond in different ways to the press of the “a” button on our keyboard. Our goal? To open or switch to a minimized/closed application, in this case, Alium Designer.

  1. If “A” is pressed and Altium Designer is not working, start the program
  2. If the button is pressed and the app is working, but is not the active window (foreground), activate it and put it in the foreground (the app is shown)
  3. If the app is running and in the foreground, then pressing the button “A” actually sends a press of the button combination CTRL+TAB to the system (written in the code as ^{tab}).
A::switchToAltiumDesigner() ;; When "A" is pressed, the function "switchTo..." is called

switchToAltiumDesigner() ;; function
IfWinNotExist, ahk_exe  X2.EXE ;; if app is not open, open it
	Run X2.EXE, C:\Program Files\Altium\AD18\   ;; here we place the address of X2.exe in our sys
if WinActive("ahk_exe X2.exe") ;; if app is open and active, switch between tabs
	Sendinput ^{tab}
	WinActivate ahk_exe X2.exe ;; if app is open, but not active, activate it on the last act. view

For further reference to the code syntax, please consult the AutoHotKey website.

Of course in our example we would lose the usage of the “a” button on our computer, here your needs and preferences come into play.

In my use case scenario, I never use caps lock, therefore what I’ve done was to create a macro keyboard layer, activated only when the CAPS LOCK button was pressed, by doing this, I lost any ability to use CAPS LOCK for its intended purpose, but again. I do not care.

NOTE: To use the CAPS LOCK it is possible to activate and deactivate it (its original function) by pressing SHIFT+CAPSLOCK. This will enable the “all caps” mode, or disable it, without triggering the Macro layer to turn on.

If you do care, with a bit of coding one could let the script recognize double presses of CAPS LOCK to activate the UPPER CASE instead of the macro layer, or anything else one might prefer.

At the end of the article, you will find a link you to see my GitLab page where you can download the code I’m running.

In a nutshell, what the code does is:

  1. Setting a few runtime variables and putting the code on stand by
  2. Monitoring caps lock to be pressed or not
  3. If capslock is pressed, then the code leaves stand by, the “state” variable toggles, and an animated gif is shown on the bottom right corner of my screen to let me know that the macro layer is active.

    To know that the macro layer is active is very important, why? Imagine you activate the macro layer without realizing, then, attracted by the search bar on Google, you start typing a web address. If you’re fast enough, in 2 seconds you will trigger the boot process of up to tens of apps, depending on how many keys are mapped.
  4. While the macro layer is active, apps can be switched, their tabs navigated, and any further action executed.
  5. If capslock is pressed again, “state” toggles and, the animated gif disappears, and the script goes to sleep.

Then, if one likes, each key can host a nice colored image of the app icon together with a graphic hint of the letter that’s usually underneath, which is exactly what I’ve done here.

How much time does this save? Well, not much while you’ll be busy setting up everything, but once everything is up and running, you’ll be able to switch apps to the press of two buttons (or one), which is satisfying.

Nadim’s GitLab Code
AutoHotkey (AHK) Script for:

Application switch
Gif show on desktop
Macro Keyboard Layer on caps lock press

Note: if you need to resize a gif online, to be shown on your screen, this tool might help a bit:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.