Using Keyboard Macros Part 2 – AutoHotKey

by dstifel

Using Keyboard Macros Pt. 2


So how the heck do you create these keyboard macros? You can’t do it just with Windows, nor with a Mac – that functionality is not included in either operating system. You need to acquire a keyboard macro program. For Windows, this is a piece of freeware, available at . (The freeware status of this program has apparently caused some rifts with the developers. There is now a claiming to be the definitive and newest version of this program. Caveat emptor – I am currently running version, the one you can download from .)

Let me reiterate here, this part of the series relates to all Windows users. Even if you don’t use the same DAW as I do (Sony Sound Forge), the software I’m talking about today will work on any of the DAW platforms you may be using.

As for Mac users, do a web search on “keyboard macros for Mac” to see what utilities are available for you to use. Though the exact syntax will differ, the concepts and general approaches I describe will – hopefully – translate to both PCs and Macs.

So, you web surf to, and download the install program. Simply double click on it once you’ve downloaded it to initiate the installation. Should be very quick.

The online documentation for AutoHotKey is valuable and pretty extensive. If you are really motivated, by all means read through it for a much fuller account of this utility. For now I want to describe the high level operation, since the documentation can be too much of a good thing if you are just beginning.

What have you done exactly by “installing” AutoHotKey? This program is now running along with Windows every time you boot up until you power down. It will not show up in your task bar. It will show up as a process in the Task Manager. The program is simply sitting in memory, waiting for you to tell it to do something. Until you do, you’d never know it was there.

The way you tell AutoHotKey to do something is to create what we call a command script, or command file. You could use a fancy word processor for this, but only if it lets you save files as text only. The formatting information in complex word processor files will completely confuse AutoHotKey and make a mess of things. Best to just use Wordpad to create and edit command scripts – and be sure to save as text only!

The command file you create with Wordpad may be named anything you wish, but the file extension, the last three characters of the file name following a period MUST be .ahk. Filename.ahk. Anyname.ahk. Once you’ve saved this file, you find it in Windows Explorer, or paste a copy to your desktop. Double clicking activates it. Just like any program, you double click on this file name to wake AutoHotKey up – the ahk extension is how AutoHotKey knows to read this file and do something with it.

You can tell if any scripts are active by checking the Windows taskbar. An active script (you can run more than one at a time) shows up as a green icon with a capital H in the center. You can right click this icon from the task bar to edit that script, pause the script (ignore it temporarily), or exit – wipe the script from memory so that it is no longer active at all.

AutoHotKey Scripts – Bare Basics

An AutoHotKey script does two things:


  1. Identifies the keyboard keys that you want to take over and give extended (or diminished) functionality to.
  2. Tells AutoHotkey when it gets one of these re-defined keystrokes, what to do with it and what commands to send down in place of that keystroke.

Let’s start with a real, simple but nontrivial example. Let’s say I want to completely turn off the F9 key.

Your script to do this would look like this:



The F9 is a “standard” key name understood by AutoHotKey. The two colons :: signify “Here follows a definition for the preceeding key.” The “return” is a built in command understood by AutoHotKey to mean do nothing more, you’re finished for this key. That little chunk of code will disable the F9 key (stay tuned for why anyone would want to do that in the first place. I have a danged good reason.)

So you type those two lines into Wordpad, you save the file as text only and give it the name “DeadF9.ahk”. Now when you double click on DeadF9.ahk, the F9 key will indeed be completely dead. It will continue to be dead until you reboot your computer, or you can exit the script by right clicking it from the task bar. You only need to activate a script once. If you try to activate it a second time, AutoHotKey will tell you it’s already running, do you want to run two copies (I have not yet found a situation where that would be useful.)

A few more conventions for scripts. You would seldom want to change the meanings of any of the alphanumeric keys on the keyboard, nor would I recommend redefining any of the punctuation keys. The ones I use consistently are control-key combinations, alt-key combos, and function keys. Such well known combinations as Ctl-C to copy, Ctl-X to cut, and Ctl-V to paste – these functions are so ubiquitous, I would not recommend redefining them either.

But stuff like CTL-U, CTL-I, Alt-M – stuff that is not universally used by Windows is fair game. In your command script, such keys are shown with a carat ^ to indicate the control key, followed by the alphabetic key. Thus Ctl-u in the AutoHotKey script would say:

^u::                              ; redefine Ctl u

And here’s another useful feature – see the semicolon in that line? The semicolon in command scripts means that AutoHotKey will ignore the semicolon to the end of the line – it is not a command for AutoHotKey, it is a helpful comment to describe in English what’s going on. It’s what programmers call self-documenting code. Use this feature liberally – scripts can get involved and hairy real fast. Leave bread crumbs to tell yourself what you’re doing.

FYI the shorthand for the Alt key is the exclamation point ! – !m would mean the Alt-m combination. The function keys are a piece of cake F1, F2, F3 etc.

A number of special keys have internal definitions, and are specified with curly braces enclosing the keyname. {Enter} = the enter key, {Tab} = the tab key, {NumPadDown} = the down arrow on the numeric pad. (See why I recommend reading the documentation? There’s far too much to cover here, I’m just trying to give you the flavor, and the basic stuff you’ll need to understand the coming examples.)

Okay, absorb this information and get ready for the next installment. I will show you a command script that will let you paste room tone over any mouse selected area in Sound Forge – with a single keypress. This makes covering a selected area with room tone just as simple as zeroing it out – except the room tone will get you past QA, and zeroing it out won’t.

Coming next in Part 3: One keystroke to cover selected area with room tone.

© 2014 David Stifel – All Rights reserved