AutoHotkey: What is it and why would I use it.

AutoHotkey (AHK) is a powerful scripting language initially intended for the creation of macros and keyboard shortcuts. With its powerful and simple syntax for key-binding and window management, it is a useful tool for any Windows user’s tool belt.

Background

I was first introduced to AHK by a coworker (John) in the summer of 2014. I had been on the search for a way to store lines of text I had to type frequently that was better than a text file and copy/paste. That summer, I acquired a barcode scanner for a project, but also experimented with using it for this as well (I printed off a sheet of bar codes containing lines of code I kept needing to add to the work I was doing). John mentioned AHK to me, and I tried it out.

I use it all the time now, with some shortcut scripts setup to run on startup, and the occasional “I need to do this thing real quick” when Python isn’t the best option (For example, see my Time Focuser article).

Overview of Syntax

A basic action that I’ll use several times throughout this overview is typing out an expresion through the Send keyword.

This would type “e” and move to the next instruction


Send, e

To create hotkey (a set of keys hit at once), specify the keys followed by :: then the desired action

This would type the letter “e” whenever “i” is hit.


i::Send, e

To create a hotstring (a set of characters typed in order to trigger an action), put :: then the string followed by a ::

To make it not matter where you type the string (you could even type it on the desktop while it beeps that you are giving it invalid input), use :*c: as the lead in set (putting a “*c” in the first pair of :’s)

When dealing with hotkeys, if you just put some text after the trigger, the action will be a replace (back space what you typed and send the other text)

This would replace any btw’s with “by the way”s


:*c:btw::by the way

Simple, but let’s go simpler

I hope you can see how easy it is to make a basic script, but the point of using AHK is to make difficult automation extremely easy.

Enter AHKGen.com.

AHKGen.com Overview

From the site:

This is a generating configuration utility for AHK scripts

In order to run these scripts, one needs to either download and install Autohotkey from the main website or have someone who has an install compile the script.

This tool allows for a very quick editor for the most common basicu usages with AHK to help you get going.

Example 1: Typing the ‘¢’ symbol

Have you ever noticed how the ‘Cents’ symbol is never on your keyboard? Most of us have just learned to deal by typing “$0.05” instead of “5 ¢” - Yes, I’m using html encoding for this blog post, but what I’m about to show you will work in any text editor that handles Unicode characters (which is just about everything except the basic Notepad). This is particularly useful when trying to make tidy/professional signs, flyers, or similar with prices in the cents range.
However, realize that the following steps apply to most (if not all) unicode symbols, so if you find yourself needing to type check marks, smiling faces, or union symbols, head over to fileformat.info and look up the UTF-16 Hex value for whatever symbol you need to use in the steps below (although, I have found googling “unicode {symbol}” and selecting the fileformat.info link from the results to work better then using their search).

Ever encounter a document or website where you wish your mouse scrolled a lot faster, but don’t want to change the scroll setting because it’s the right speed on smaller docs?

Here’s where the power of AHK really starts to shine through. I can create a shortcut to word on the desktop and use the properties to assign a “shortcut key” to open it, but with Autohotkey, I can have my macro be smart enough to bring it to the front if it is open, and open it if not.

There’s a provided function for this on AHKGen.com, so we’ll go ahead and use that to make Word come to the front if we hit CTRL + Alt + w.

All of these examples and more are included in the example configuration available on AHKGen.com



Other resources:

For more examples of great ideas to automate using AHK, check out these other articles (Note that these articles were mostly written before the existence of AHKGen.com, so fail to mention it) :



Some Final Notes:



Call for comments

On this article in particular, I’m interested in hearing what scripts/macros you’ve found to be useful and are willing to share.