Save Time by Saving Keystrokes with AutoHotkey

Autohotkey LogoAutohotkey (AHK) is very powerful software. And it is exactly the type of tool that we want to highlight here at DIY Ivory Tower. At the most basic level, AHK allows you to create your own keyboard shortcuts in Windows. [Mac users should check out this post from Profhacker describing Mac software called TextExpander. It also mentions a few other Mac and Windows text expanders that can accomplish at least some of what AHK can do.] I started using AHK for very simple tasks like having my computer type my phone number when I press a certain combination of keys. I’ve got other hotkeys set for my name, a complex part (but not all) of my email password, my address, and my email address. These shortcuts come in very handy when filling out forms online or sending simple emails. Once you start using the software and reading through its user guide, however, you’ll quickly see that it is capable of very much more.

Enjoying the conveniences of AHK requires some initial effort. After installing the software on your PC, you’ll need to create a script file which contains the hotkeys that you’ve written. Once you’ve written your script, you place it in your computer’s startup folder. Since it loads at startup, AHK continually monitors what you type and looks for combinations of keystrokes that are designated as hotkeys in your script. Don’t freak out. You won’t need any computer programming experience in order to create the script file. The code used to create the hotkeys is quite logical and very simple. And you can learn everything you need to know from the user’s guide and website’s forums. For example, in order to have my computer type my last name when I press the Windows Key and the “C” key at the same time, I have the following line of code in my AHK script.

#c::Send Costanzo

In AHK’s code the number sign or hash represents the Windows Key. Thus, this bit of code simply dictates when the Windows Key is pressed with the “C” key, the word Costanzo should be typed.

Below are some other uses of AHK which I think are particularly valuable, especially for graduate students. And I should note that I’m by no means an expert user. If you explore the user’s guides and forums at, you’ll see an amazing array of ways to automate actions and functions on your PC with this software.

Typing Words or Phrases You Use Often

I noted above that I’ve created hotkeys for various pieces of common text. But pressing a hotkey using the Windows, Ctrl, or Alt keys doesn’t typically make for a smooth and efficient typing experience. Since I study early Washington, DC, for example, I might want to save myself the effort of typing the word Washington a thousand or so times over the course of my dissertation. However, I wouldn’t want to create a hotkey that requires me to lift my hands off of the keyboard mid-sentence in order to locate the Windows Key and then hold it down it with my thumb while I maneuver my index finger over to the “W” key. It wouldn’t be hard, but it obviously wouldn’t be more efficient than typing out the full word unless I got very accustomed to making that strange keystroke.

For words and phrases that you use often when typing, it’s best to create a hotstring rather than a hotkey. With a hotstring, you tell the software that when it sees you type a certain set of letters in a particular order, it should replace those letters with new text. Here’s the shortcut for typing the word Washington in my script:


This code tells the computer that when it sees me type a “w”,  an “a”, and then a period, it will transform “wa.” into “Washington” as soon as I hit the Space Bar, the Enter key or another punctuation mark (the actions that activate a hotstring).

Typing Large Blocks of Oft Reused Text

The same type of hotstring works for typing in large blocks of text. I find this to be particularly useful when managing email. I’ve got my AHK scrip set to provide text blocks briefly describing my research for introductory emails, explaining how to find my office in the wildly complex building where my department is located, and spelling out the options for students who email me to say that they are sick and can’t make a discussion section. Here’s the code for that last item. As you might guess, the {Enter} command produces hard returns.

::sicktext::Hi ________,{Enter}{Enter}Sorry to hear you aren't feeling well. If you feel better and would like to attend a different section later in the week you are welcome to do so. Just check out the course website for the list of sections and let me know if you plan to attend one so I can alert the other TA.{Enter}{Enter}Thanks,{Enter}{Enter}Adam C.

So once I’ve typed “sicktext” and pressed the Space Bar or the Enter key, all I have left to do is fill in the student’s name. These hotkeys work wonders for those emails where you have to convey information that you’ve typed out a hundred times over the course of the school year.

Typing Out Today’s Date

With the following piece of code in my AHK script, each time I press the Ctrl, Shift and “D” keys together, my PC types out the current date in the following format: YYYY_MM_DD. Note that in the AHK code the carrot symbol (^) stands for the Ctrl key while the Plus Sign stands for the Shift key.

FormatTime, CurrentDateTime,, yyyy_MM_dd
SendInput %CurrentDateTime%

This hotkey works great for naming date specific files. (Bonus Tip: When using dates in the names of files or folders on your computer, keep the computer’s alphabetization logic in mind when choosing your date format. If you type in dates the way that American’s typically do (MM-DD-YYYY) then your files will remain in order only if they all come from the same year. Once you add dates from separate years, they will be grouped first by month. Instead of falling into this trap, think like your computer does when naming files and folders and start with the year followed by the month and then the day.)

Paste the Contents of the Clipboard as Unformatted Text

Research in the digital age requires what seems like constant copying and pasting of text from one source or program to another. And typically it’s the text – not the formatting – that you wanted to paste. Often enough, however, you find yourself surprised by the strange and grotesque ways that one piece of software might interpret the formatting given to text by another. In programs like Word, you’ve got the option to go to Paste Special and select “unformatted text” as your desired paste option. And with AHK you could create a hotkey that automates that process in Word. However, you won’t always be working with Word when you need to paste just the content of some text and not the formatting. Recent updates to Zotero for instance, now allow for HTML formatting in the notes field. Which means that if you copy and paste into that field, you might be bringing along unwanted formatting. The piece of code below strips copied text of all formatting and pastes only the text no matter what program you are working with. It is activated when I press the Ctrl, Alt, and “Z” keys together. I chose this hotkey primarily because it is one I can easily type with one hand. The Ctrl, Alt, and “V” hotkey which might have been more logically associated with the universal paste hotkey of Ctrl + “V” felt a bit awkward when I tried to type it.

Clip0 = %ClipBoardAll%
ClipBoard = %ClipBoard%
Send ^v
Sleep 50
ClipBoard = %Clip0%
VarSetCapacity(Clip0, 0)

Obviously this code is more complex than other’s I’ve included here. And I’ll admit that I don’t possess the programming knowledge to have written this myself. However, thanks to the robust community of AHK users in the AHK forums, it’s very easy to find prewritten code that meets your needs. You can even ask the experts in the user forums to help you out if you are stumped by a piece of code.

Add Quotes around All the Text from the Beginning of a Line to the Location of the Cursor

You might be asking yourself what the possible utility is for a hotkey like this. If you are including a quotation in your prose, what is the likelihood that you forgot to open the quotations or that it begins exactly at the start of the line? That’s a perfectly valid question. And the answer is that this hotkey has nothing to do with writing prose. I designed this hotkey for use in web search boxes. I can’t tell you how many times I’ve typed search terms into a search box for Google or JSTOR or any other site with a search engine but realized after I began typing that I should be entering this search phrase in quotations in order to get more accurate results. The code below creates a hotkey that solves this problem.

^'::SendInput "{Home}"

Once I’ve typed text into a search field that I want surrounded by quotes, I simply press Ctrl and the Apostrophe/Quotation Mark key at the same time. This hotkey types out one quotation mark at the end of the text where the cursor currently rests, moves the cursor to the start of the line with the Home key and then types another quotation mark.

Open Notepad (or any Program) with a Hotkey

This one really doesn’t need much explanation. The code below allows me to open the Notepad program with the press of the Ctrl, Alt and “N” keys. You can see from the code that the script first checks to see if an untitled Notepad file is already open that it should simply make the current active window. Otherwise it runs the program.

IfWinExist Untitled - Notepad
Run Notepad

You can set AHK to run all of your most oft-used programs with hotkeys. The productivity logic behind this is simply that each time you raise your hand from your keyboard to grab the mouse or use the touchpad, you are wasting time. The more work you do with your hands on the keyboard the more efficient your computing experience will be.

Typo Prevention

Finally, AHK can also be used for simply typo prevention. At one point a particularly enterprising AHK user compiled a script with all of the commonly misspelled words from a list of them at Wikipedia. The script she created asked the computer to look for those misspellings and correct them when it saw them. This script basically provides the functionality of Microsoft Word’s autocorrect feature but it applies it to your entire computing experience, no matter what program you are using. The script has since been improved by other members of the AHK community. You can download a ready-to-run version of it from the Other Downloads section of the AHK website. I’ve been running this script for a while in addition to the one with my own hotkeys. And, although I’ve disabled some parts of the script, I’ve found it generally quite helpful.


As I said at the start, AHK is very powerful software. And it is definitely worth the brief time it takes to learn to craft your own scripts. Beyond providing some actual content for your work, there are very few computing tasks AHK can’t help you automate. I’m constantly dreaming up new ways for it to improve my life. As I drafted this post I began to think that I should teach AHK a hotkey which would highlight the last word I typed in my word processor. Since I often highlight words that I’m not completely happy with when writing a first draft, such a hotkey might make that process at bit more seamless and, consequently, keep me in the flow of writing. At some point in the coming weeks I plan to write up a post which explains how to use AHK and Microsoft Word to easily markup and comment on student papers electronically. Keep and eye out for that.


4 responses to “Save Time by Saving Keystrokes with AutoHotkey

  1. Pingback: Use AutoHotkey, Microsoft Word, and doPDF to Grade Papers Electronically « DIY Ivory Tower

  2. Pingback: Create Zotero Hotkeys in Word for Faster Citation « DIY Ivory Tower

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s