AutoHotkey Tip of the Week: Understand How Hotstring Activating Text Works

Sometimes We Limit Our Scripts by Not Grasping How AutoHotkey Features Respond

In AutoHotkey, we use Hotstrings for automatic text expansion and replacement—as in the extensive list of common misspellings found in the AutoHotkey AutoCorrect.ahk script. After loading this series of Hotstrings, if you misspell one of these words, AutoHotkey instantly corrects it. I’ve included this as a standard part of my main AutoHotkey script and often watch the Hotstrings in action when they correct one of my typos or misspellings.

Beginning AutoHotkey Hotstrings 200pxWhenever a Hotstring fires, it resets and waits for the next one. Most commonly, this occurs when we type a space, period or other punctuation as a Hotstring recognizer. One might fall prey to the misconception that every such space or punctuation key press causes a Hotstring reset, but not so. Hotstring monitoring only resets when a Hotstring event occurs (or with a mouse click or cursor movement). That means we can include spaces and punctuation in the activating strings (or Hotstring definitions) which appear after the first double-colon.

Light Bulb!Most AutoHotkey users might understand this fact about Hotstring activators, but I write about it here for those of us who either never fully realized the importance of this aspect of Hotstrings or we just forgot. Knowing this fact allows for a number of additional types of Hotstrings rather than limiting ourselves to standard text expansion and replacement. A perusal of the AutoHotkey AutoCorrect script lets us peek into how we can take advantage of this aspect of Hotstrings.

Include Spaces and Punctuation in Hotstring Activators

You can use almost all the characters on the keyboard in your Hotstring activating string (between the two sets of double colons). The backtick and a couple of other characters do require escaping with the backtick character but spaces and punctuation can appear in the activating text without special treatment.

Note: Keys that do not produce a character such as Shift, Ctrl, and Alt cannot appear in the activating string. The cursor movement keys also cause a reset of the Hotstring recognizer with no apparent method for use in the activating string—unlike the replacement string (e.g {left 3}).

Uses for End Characters in Hotstring Activators

One of the most common uses of this Hotstring feature involves fixing the punctuation in contractions. As shown in the AutoCorrect file, a number of common typos occur in contractions:


This Hotstring automatically replaces the errant semicolon with an apostrophe. This error frequently occurs because the two keys sit next to each other on the keyboard. However, many other possible contraction errors do not appear in the AutoCorrect file, for example:


(If you find that you often hit the semicolon key accidentally, you may want to add a number of these Hotstring contraction corrections to your AutoCorrect file.)

Use Spaces in Hotstring Activating Text

We might forget that we can use spaces in our Hotstring activating text without resetting the recognizer (40 character limit). For example, the AutoCorrect file contains the following grammatical errors:

::may of::may have
::might of::might have

When typing, AutoHotkey ignores any space characters until the entire phrase fires the Hotstring replacement. This makes a number of other types of corrections possible:

::don't no::don't know 
::can not::cannot

Note: At times you may want to keep the space in “can not”, (e.g. “I can not only play backgammon but love tiddleywinks.”)

You can use the same technique to fix hyphenated words:

::user friendly::user-friendly

Although depending upon the usage, you may not need a hyphen at all.

Add Special Characters with Rarely Used Punctuation Keys


At one point, I added the word résumé to my AutoCorrect file as a specially activated Hotstring (as discussed in Chapter Two of my book, Beginning AutoHotkey Hotstrings: A Practical Guide for Creative: AutoCorrection, Text Expansion, and Text Replacement). However, adding each word distinguished by unusual foreign letters can get tedious:


Plus, I occasionally run into many other words that I would like to type without including each in the list. At those times, when I want to enter the special character with the simple press of an additional key without the use of the special character lookup table found in many word processing programs, I can resort to adding a little-used key such as the backtick ( ` ) to create a quick replacement:


Note: Since the backtick acts as the escape character, you must escape it with another backtick (as shown above). (For the list of characters requiring the use of the backtick, see the #EscapeChar documentation.)

I use the immediate-execute option * and inside-word option ? to allow instant replacement regardless of location in a word. For example, I can type “re`sume`” on the fly to create the word “résumé” without resorting to a dedicated Hotstring for the word. Now, whenever I want to change an e into an é, I merely hit the backtick key just after entering the letter e.

Note: Rather than using the backtick key, I could just as easily implement the little-used backslash key ( \ ) (or another idle key) as the activator.

This approach to Hotstrings works great if you only need a few special characters available. But, if you use a lot of them, then remembering all the key combinations can get confusing. The foreign variations of the letter e alone offer a challenge (æ, ë, ê, è, é).

Next time, I’ll offer another tip from the Beginning AutoHotkey Hotstring book about how you can make adding special characters to your documents easy while limiting the number of Hotstrings you must remember.

Click the Follow button at the top of the sidebar on the right of this page for e-mail notification of new blogs. (If you’re reading this on a tablet or your phone, then you must scroll all the way to the end of the blog—pass any comments—to find the Follow button.)


This post was proofread by Grammarly
(Any other mistakes are all mine.)

(Full disclosure: If you sign up for a free Grammarly account, I get 20¢. I use the spelling/grammar checking service all the time, but, then again, I write a lot more than most people. I recommend Grammarly because it works and it’s free.)

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 )

Facebook photo

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

Connecting to %s