Technology in terms you understand. Sign up for the Confident Computing newsletter for weekly solutions to make your life easier. Click here and get The Ask Leo! Guide to Staying Safe on the Internet — FREE Edition as my thank you for subscribing!

A brief overview of AutoHotkey

It’s not uncommon to want to remap keys on your keyboard or create keyboard
macros that essentially type a large series of characters for you in response to
just a couple of actual keystrokes. AutoHotkey is a tool that does this and much,
much more. I use it heavily.

In this video for an Ask Leo!
webinar
, I’ll show off a few of its features.

]]>

View in HD (1280×720)

Transcript

AutoHotKey is a keyboard remapping and macro creation tool. Now this tool tends to be a difficult one to understand or to describe. You get it at autohotkey.com. The default download for it – I used Installer for AutoHotKey Basic, which is plenty for the average user. What I’m going to do is run the .ahk file, the autohotkey file, that I have on my machine that will actually cause AutoHotKey to be loaded.

So, all that’s really happened here is we now have this AutoHotKey icon down in the notification area. If I now fire up a utility like Notepad, what AutoHotKey allows you to do is define keyboard macros; I have several defined. I chose to use the left bracket, I’m sorry, the right bracket key as the Escape key if you will, for whatever it is I might want. So in my particular case, if I type ]eg, you get my standard email signature typed in. If I type in ]eh, I get the longer signature typed in. That turns out to be very powerful because you find yourself typing the same thing a lot very often if you are doing email or as in the case of myself, I also moderate a mailing list, a Corgi emailing list, and this is one of the standard repsonses that I find myself sending out all of the time. So rather than typing it from scratch every time, three keystrokes and it’s part of the email.

So, how did all of this get defined? Well, let’s have a look at that .ahk file that I opened up and you’ll see. So this is AutoHotKey’s probably biggest drawback is that because it is so incredibly powerful, it is also a little on the obscure side to program. You do end up having to learn a bit of a programming language, but it’s for fairly simple operations; it’s actually fairly simple language. You can see here (let me go to one of the ones that uses my…that includes my signature). Here’s the Standard Ask Leo! Thanks for asking text – you can see the ]eh is defined this way and then it’s just a series of ‘Sends’ where it’s actually sending in keystrokes and it doesn’t matter what application you happen to be sending them into. I sent them into Notepad a few moments ago, but you can also send them into your favorite email program; you could send them into Word; you could send them into a command prompt; you could send them into just about anything since AutoHotKey operates at the system keyboard level which means any application that is blindly asking for keystrokes from Windows has AutoHotKey placed in front of it so that whatever AutoHotKey does, gets sent to the application as if they were being typed for real.

AutoHotKey actually allows you to do a lot of different things. I happened to use it for a couple of scenarios. This one I wanted to show because it’s fairly interesting. Paste in Command prompt. The Command prompt which is what we use to refer to this window; it doesn’t have Windows standard keystrokes. You can’t use ‘Ctrl C’, ‘Ctrl V’ kinds of things, but you can make it do that. For example, if what this is saying is if the current window is a console window and the keystroke that has just been pressed is a Ctrl-V (which we normally see as ‘paste’), then automatically sends the input from the clipboard to that application.

There are several different things here that are really interesting and just sort of touch on the power of AutoHotKey. One is we’ve actually remapped a keystroke. This Ctrl-V which normally doesn’t do anything in Command prompt, it now has functionality. And we’ve restricted it to a specific type of window; in other words, a console window or the Command prompt. We’ve gained access to the clipboard and sent that in.

Another common use of AutoHotKey as I said is to remap keystrokes. This particular one is a remap of the Windows key plus ‘E’. I don’t actually have this set up on this machine, because I don’t have Explorer 2 turned on, but what this does is allows you to define whatever you want the Win E key to do. Now, you’ll notice that Win E by default, in Windows, fires up Windows Explorer. So what I’ve done is I’ve overridden that. Win E on my systems with AutoHotKey installed will (if it’s not already running which is what this line tells us) will go and run from scratch, Explorer 2 which I use instead of Windows Explorer. If the window does exist, it just activates it; in other words, it brings the existing copy of Explorer 2 to the foreground.

The actual AutoHotKeys interface is pretty sparse. It’s mostly about debugging. You can actually see the activity that its taken here as we’ve done things which is basically a log of actions. You can reload the script which is this .ahk file that I’ve created; you can edit it; you can pause it which basically turns everything off. Which makes everything that you might have typed not be recognized until you re-enable it and so forth.

And finally, the one last thing that I think sometimes people are a little concerned about is if I type in…so I have a macro in AutoHotKey for the current date (so today is 13 Nov 2011) what’s interesting to note is if you’ll look carefully while I do that, I type the first character; I type the second character and as soon as I type the third character and AutoHotKey recognizes that, this is a three-character macro that it is supposed to act on. The first thing it does before it actually inserts text is it executes three backspaces to get rid of the three-character macro. So it all happened quickly but the bracket the ‘t’ and the ‘d’ that I typed, the first two characters of which were actually just typed into the Command prompt were erased. Now, that’s important to realize for some programs and I say that because the programs that act immediately on keystrokes can sometimes get confused by this. So that’s when you end up having to define single-character macros only but most of the time most text editing programs, most email that’s just using a regular plain text kind of editor, this ability to use an aribitrary length flag or macro name or keystroke sequence that you would use to fire off an AutoHotKey macro is very powerful and is transparently and automatically removed once it replaces that macro that you’ve typed in with the text that you’ve programmed for that macro. The ability to remap keystrokes is probably one of the more common questions that I get and I tend to point people at AutoHotKey specifically because of its power. There is very little that I have found that I’ve been unable to do with AutoHotKey. There is one scenario that I use almost daily where instead of actually having AutoHotKey programmed for a particular sequence of characters, I have it…it actually allows you to select the file. I cannot show you that here because it’s not configured properly for this virtual machine, but what this particular macro does is on a three-character sequence, it will open a file ‘open dialogue’ box on a particular folder that I’ve created (you can see that actually down here; it’s my folder of stock answers) and allow me to select a file and then it will type in the contents of that file as if I were typing it right then and there. That’s one of the ways that when I respond to somebody in email, as you know many of the questions I got are repeats rather than type the same answer over and over again I simply have a collection of files that contain the answer and I simply tell AutoHotKey go take the contents of this particular file and type it into my email messages as if I were typing it live. That’s the kind of power that’s available in AutoHotKey.

So what does the Window spy on the menu do? I have no idea; I’ve never used it. Apparently, it lets you spy on Windows. I’m not sure exactly; it’s basically looking at – it’s telling you mouse positions and a few other things about the Window information that’s actually not normally available to a casual Windows user. Much of this information here such as visible Window text, status bar text, Window positions and so forth – they are sometimes things that you might want to use in your AutoHotKey macros to configure or control a specific application.

Do this

Subscribe to Confident Computing! Less frustration and more confidence, solutions, answers, and tips in your inbox every week.

I'll see you there!

3 comments on “A brief overview of AutoHotkey”

  1. Head over to Donation Coder programming school to learn how to unlock HUGE amounts of potential in AHK. And check out Skrommel’s programs. The amount of really powerful stuff he can code in a really short time is amazing.

    Reply
  2. AutoHotkey changed my life after I discovered it a couple of years ago at http://www.icpug.org.uk/national/features/060305fe.htm, where “Comparing it, (AutoHotkey), to the Windows Scripting Host is like comparing an electric circular saw to a breadknife” sums it up very well.

    The worst one can say about it is that one is tempted to do so many things with it that it’s a distraction from everything else. Until then I’d been using Macro Express for ten years, but it didn’t take long to convert my favourite macros, one of the first being to correct a transposition, which I use to correct typos in Word, text editors, emails, even here.

    I also find it useful to keep an eye on what Dropbox is up to, rather than hover over that little icon. Especially useful when one has a TrueCrypt volume in one’s Dropbox, and wishd to ensure it’s synched before hibernating.

    And it gets more powerful all the time, mind-bogglingly so, in fact.

    Reply
  3. How does this compare to Phrase Express? I’ve just started using Phrase Express and find the UI much easier. Does anyone have any thoughts or experience with using both or either of these products? Thanks.

    Reply

Leave a reply:

Before commenting please:

  • Read the article.
  • Comment on the article.
  • No personal information.
  • No spam.

Comments violating those rules will be removed. Comments that don't add value will be removed, including off-topic or content-free comments, or comments that look even a little bit like spam. All comments containing links and certain keywords will be moderated before publication.

I want comments to be valuable for everyone, including those who come later and take the time to read.