Text Expansion, Macros, and More with AutoHotkey for Windows

Man playing AccordionText expansion generally refers to the way a few typed letters can expand into entire words, sentences, or even paragraphs. It’s a simple idea but an incredible time-saver.

We’ve talked about text expansion tools before on ProfHacker, but we’ve tended to focus on the Mac. What about text expansion for Windows? I’d like to recommend AutoHotkey, a powerful, open-source and free scripting tool that handles text expansion but also so much more. I’ve been using AutoHotkey for years, and it’s become such an integral part of my workflow that I often forget I’m even using it.

AutoHotkey runs in the Windows system tray whenever you load a *.ahk file. (Pro Tip: I placed a shortcut to my hotkeys.ahk file into my Startup folder, so my hotkeys load whenever I boot my computer). The .ahk file is simply a plain text file that contains your hotkey and macro scripts. You can edit the file in any plain text editor (I use Notepad++), and your .ahk file can contain any number of commands, written in AutoHotkey’s scripting language. The scripting language is easy to use, and there are plenty of examples you can borrow to get started.

Here are just a few AutoHotkey commands I regularly use (copy and paste them as plain text into your own AutHotkey file to use them yourself). As an example of text expansion, here’s an easy one:

::btw::By the way

This little script tells AutoHotkey that whenever I type btw, it should replace those three letters with the phrase “By the way.” And it works across all applications—your email compose windows, your word processor, and even just now it was replacing “btw” for me in this very post, so I had to temporarily pause AutoHotkey (by right-clicking on the icon in my system tray).

Technically this is not text expansion so much as it is text replacement. Which means you can use AutoHotkey to correct frequently misspelled words or proper names that are simply a pain to type. For example, at some point in my distant past I added this line to my hotkeys.ahk file:


So now, whenever I type zizek, it automatically becomes Žižek. (Thankfully I don’t use this script very often any more.)

But text expansion/replacement is just the start of what AutoHotkey can do. You can create shortcut keys, like this:

#w::Run C:\Program Files (x86)\Wunderlist\wunderlist.exe

AutoHotkey interprets the pound sign as the Windows key, so this snippet assigns an action to the Windows-W combination, in this case to open the task manager Wunderlist. You can create shortcut keys for any application, or really, for any task you regularly perform. Consider this more complicated example, which I use whenever I’m entering grades into Blackboard:

InputBox, UserInput, Grade, Enter Grade., , 240, 240
if ErrorLevel
    MsgBox, CANCEL was pressed.
Send {TAB 49}
    SendInput {Raw}GRADE: %UserInput%. See the comments in the attached file(s).
Send {TAB 3}
Send {Enter}

I won’t walk through this entire script, but it essentially does the following: if I type Windows-G, a dialogue box pops up, where I enter the letter grade and press return, then AutoHotkey jumps to the “Feedback to Student” form in Blackboard (that’s the 49 tabs), where it pastes the grade as well as an instruction to “see the comments in the attached file(s).” Finally AutoHotkey presses the upload file button for me, opening up another dialogue box, where I find the student’s paper to be uploaded.

What was once a minor but tedious part of grading is now fully automated for me.

Finally, here’s one more useful control script that illustrates the power of AutoHotkey:

^SPACE::  Winset, Alwaysontop, , A

The caret (^) refers to the control key, so this means whenever I press CTRL-spacebar, the current window will always remain on top, even when it’s no longer the active window. This is handy, for example, if you want a calculator program to always remain in front of your other windows. Pressing CTRL-spacebar again on that window will deactivate the “always on top” action.

One more bonus tip for AutoHotkey: my main hotkeys.ahk file resides on Dropbox, so the same hotkeys and shortcuts are available to me no matter if I’m working on my home computer or my work computer.

These scripts are barely scratch the surface of what you can do with AutoHotkey. You can parse files with RegEx, automate mouse functions, manipulate your clipboard, and much more.

Do you have “recipes” you can share for your own hotkeys, text expansion shortcuts, or macros? Let us know!

Creative Commons Hamburg photograph courtesy of Flickr user Andree Kröger

Return to Top