Improve your workflow with AutoHotkey

This post is the first of a series where we’ll review some of the applications that we find useful and use on a daily basis. To kick off, we’ll look at AutoHotkey, an old favourite of ours.


Do you ever wish you could automate those repetitive tasks that you do each day? Well, with AutoHotkey you can.

Screenshot of AutoHotkey script
AutoHotkey is a free, open-source utility for Windows that allows you to automate tasks or commands. Macros can either be written by hand or you can use the macro recorder that’s included as part of the installation to do this for you. Any key, button or combination of same can become a hotkey.

You can also convert any script into an executable file that can be run on computers that don’t have AutoHotkey installed (useful if you want to re-map the keys on a colleague’s keyboard for example, not that we would condone this sort of behaviour, of course!).

It can also be used to create applications with user-interfaces such as the text substitution application, Texter created by one of the guys over at Lifehacker.

The following may seem a little geeky at first, but bear with us, it doesn’t have to be that way!

Installation and Setup

The first stage is to download and install AutoHotkey. Whilst you can create as many AutoHotkey scripts (which have an .ahk file extension) as you like and have any number running at the same time, we’d suggest that you start by modifying AutoHotkey.ahk which is created when you install AutoHotkey using your favourite text editor.

Our text editor of choice is Sublime Text, which we use for all our coding (indeed, this very post was written using it in conjunction with the It’s All Text extension for Firefox), but Notepad will suffice. We would not recommend using Open Office Writer, Microsoft Word or any other word processor for this purpose as the script files need to be in a plain text format.

General Notes

In order to see any changes you make to your script, you will need to reload AutoHotkey by right-clicking on it’s icon in the task tray and selecting the ‘Reload this script’ option.

Whilst you can run any .ahk file by double-clicking it, by adding a shortcut to the file in the Windows startup folder, the script will run automatically when your machine starts. In Windows 7, the startup folder is usually c:Users[username]AppDataRoamingMicrosoftWindowsStart MenuProgramsStartup and is c:Documents and Settings[username]Start MenuProgramsStartup in Vista.

Using AutoHotkey

A couple of things before we start; lines that start with a semicolon (;) or blocks of text surrounded by /* */ are comments and aren’t executed.

Shortcut keys will typically utilise the Control, Shift, Alt and Windows keys which are defined below.

AutoHotkey Modifier Keys
Modifier Abbreviation .ahk Symbol
Control key
Alt Key
Shift key
Windows key

For example, to execute a command using Ctrl-Shift-v your .ahk script will contain ^+v.

You can also use keys, like Tab, Enter, Up, Down, Left, Right, and Backspace by wrapping them in curly brackets. eg {Enter} or {BS}

Script and Snippet Samples

You can create commands to run your favourite applications, so, in the following example, Win-z will launch a website in your default browser:


In the next example. we’ll launch Notepad using Shift-Ctrl-n

+^n::Run notepad

Another application of AutoHotkey is to use it for text substitution, which is useful for those phrases and words that you type all the time, such as email and forum signatures. The trigger for each text snippet can be anything you choose.

The following examples should be self explanatory but essentially, in the first example you would type btw and AutoHotkey would expand it to by the way and in the second, sig would expand to auto-type a forum or email signature.

::btw::by the way
::sig::Kind Regards, John Smith{Enter}{Enter}Company Name{Enter} |{Enter}

Here are some examples from my main AutoHotkey script:

Clipboard Stripper

This will strip formatting from the clipboard. Either use your normal Ctrl-V to paste the full version or use Win-V to paste the plain text version.

clipboard = %clipboard%
SendPlay ^v

Dedicated minimize key

Personally I never use the CapsLock key so I’ve turned it into dedicated minimize key for the application that has focus.


Keep on top

Need to keep an application on top of all others regardless of whether it has focus? Some applications provide this functionality, but most do not. Here’s how to add this functionality to any application:

;always on top  Win + t to toggle
#t:: Winset, Alwaysontop, , A

Hidden files

By default, Windows hides certain types of files. Although you can change the settings within the depths of Windows Explorer, it’s much quicker this way:

; Win + H toggles hidden files on and off
RegRead, HiddenFiles_Status, HKEY_CURRENT_USER, SoftwareMicrosoftWindowsCurrentVersionExplorerAdvanced, Hidden
If HiddenFiles_Status = 2
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, SoftwareMicrosoftWindowsCurrentVersionExplorerAdvanced, Hidden, 1
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, SoftwareMicrosoftWindowsCurrentVersionExplorerAdvanced, Hidden, 2
WinGetClass, eh_Class,A
If (eh_Class = "#32770" OR A_OSVersion = "WIN_VISTA")
	send, {F5}
Else PostMessage, 0x111, 28931,,, A

File Extensions

In later versions of Windows, the file extensions for known file types are hidden by default. Whilst you can change the settings in the Control Panel, here’s a quicker way:

; Win + y toggles file extensions on and off
RegRead, HiddenFiles_Status, HKEY_CURRENT_USER, SoftwareMicrosoftWindowsCurrentVersionExplorerAdvanced, HideFileExt
If HiddenFiles_Status = 1
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, SoftwareMicrosoftWindowsCurrentVersionExplorerAdvanced, HideFileExt, 0
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, SoftwareMicrosoftWindowsCurrentVersionExplorerAdvanced, HideFileExt, 1
WinGetClass, eh_Class,A
If (eh_Class = "#32770" OR A_OSVersion = "WIN_VISTA")
	send, {F5}
Else PostMessage, 0x111, 28931,,, A

Add a Timestamp

Here’s how to quickly add today’s date to a document or file:

; t0 to insert today's date in the format dd-MM-yyyy
EnvAdd, CurrentDateTime, +0, days
FormatTime, CurrentDateTime,%CurrentDateTime%, dd-MM-yyyy
SendInput %CurrentDateTime%

We use a great free personal notes manager called Cintanotes to manage our To-Do lists and use different variations of the following snippets to quickly tag items according to their due dates:

; d0 to insert today's date in the format yyyy-MM-dd
EnvAdd, CurrentDateTime, +0, days
FormatTime, CurrentDateTime,%CurrentDateTime%, yyyy-MM-dd
SendInput %CurrentDateTime%

; tomorrow
EnvAdd, CurrentDateTime1, +1, days
FormatTime, CurrentDateTime1,%CurrentDateTime1%, yyyy-MM-dd
SendInput %CurrentDateTime1%

; in 7 days
EnvAdd, CurrentDateTime7, +7, days
FormatTime, CurrentDateTime7,%CurrentDateTime7%, yyyy-MM-dd
SendInput %CurrentDateTime7%

Adjust the volume on your PC

The following code snippet will allow you to turn up or down the volume of your PC’s soundcard in 5% increments:

; Ctrl+NumpadSub (-) decrease volume, Ctrl+NumpadAd (+) increase volume
$^NumpadSub::Send {Volume_Down 5}
$^NumpadAdd::Send {Volume_Up 5}

Windows Snipping Tool

In Windows Vista we saw the introduction of the Snipping Tool which is a great utility for taking screenshots. Unfortunately, not only did Microsoft hide this away, but they didn’t provide a means of easily running it. This is easily fixed by adding the following code to your AutoHotkey script which will load the Snipping Tool when you use the PrintScreen button:

PrintScreen::Run, "C:WindowsSystem32SnippingTool.exe"

If you’re using 64-bit version, then you’ll need to use this instead

PrintScreen::Run, "C:WindowsSysnativeSnippingTool.exe"

Of course, if you use SnagIt or any of the plethora of other screen capture applications out there, you can also apply this script to them.

In Conclusion

This is just a flavour of what you can do with AutoHotkey. If this post has whet your appetite, then head on over to their website to find out more or join their friendly forums if you need help.

If you have a favourite snippet or script then why not share it in the comments below.

This entry was posted in Software and tagged , . Bookmark the permalink. Both comments and trackbacks are currently closed.

One Comment

  1. Posted 10 December 2011 at 9:10 pm | Permalink

    AutoHotkey stands out because of the unique and powerful way it manipulates macros from user-defined hotkeys. But, one of the challenges that users have to face is to remember which hotkey is attached to which macro. The Enterpad easily solves this problem…