Beginning Tips for AutoHotkey Hotstring Text Correction and Text Expansion (Part 1: Hotstring Options * and ?)

Practical Ways to Use Instant Replacement (*) and Internal Word Text Replacement (?) in Your AutoHotkey Hotstring AutoCorrect Script

*         *          *

This is the first in a series of AutoHotkey blogs with tips for getting the most out of Hotstring text expansion. This first blog will explore the use of the asterisk (*) and question mark (?) Hotstring options to add more power to your personal AutoCorrect script. In the following weeks, I will discuss practical ways to use other Hotstring options—including a method for adding a pop-up menu for selecting alternative Hotstring replacements. 

*         *          *

A little while back I talked about running an AutoHotkey AutoCorrect script to quickly fix commonly misspelled words on-the-fly in any Windows program or Web page editing field. Implementing a Hotstring replacement or text expansion is as simple as adding one line of code to your AHK file:


The word sitting between the two sets of double colons (yaching) is misspelled while the corrected replacement (yachting) appears after the second set of double quotes. Once the file is loaded, every time you type “yaching” followed by a space, it immediately changes to “yachting.” By including a line of code for each commonly misspelled word, anyone can add an AutoHotkey AutoCorrect program to their Windows computer. The beauty of using AutoHotkey is that, unlike most AutoCorrect features found in word processing programs, the AutoHotkey autocorrect will work in any Windows program. (See “Add AutoCorrection to All Your Windows PC Programs with AutoHotkey” to get started.)

While it is easy to include the provided list of commonly misspelled words in your AutoHotkey script, there is much more that you can do to personalize and add power to your AutoCorrect app by using Hotstring options

*          *          *

Beginning AutoHotkey Hotstrings 200pxAs a convenience for people who want to get this entire series (plus more) in one place, I have now published the e-book Beginning AutoHotkey Hotstrings which is available on the ComputorEdge E-Books site (in three formats—EPUB for mobile devices, MOBI for Kindle, and PDF for printing and computer) and through Amazon. Regardless of whether you’re interested in the book or not, it’s worth your time to peruse some of the blogs linked at “Beginning AutoHotkey Hotstring Techniques” found under the “AutoHotkey Topics and Series” tab in the top menu bar. They just might inspire your next AutoHotkey script.

*          *          *

Hotstring Options

The asterisk (*) is one of the most useful Hotstring options because it causes the replacement to trigger immediately without hitting a space bar or punctuation key. While is most cases you will want a string replacement to fire only when you do hit space or add other punctuation, there are times when you don’t want a trailing space or character. For example, as discussed in the online documentation, when filling in a blank in a Web form, you won’t want to include a trailing space with your e-mail address. Resolve this problem by adding an asterisk (*) option between the first two colons in the line of code:


ComputorEdge AutoHotkey E-BooksNow, whenever j@ is typed the complete e-mail is inserted the instant that the @ key is hit. (The @ is used as the last character of the Hotstring since it is highly unlikely that it will ever occur in a regular word.) While the e-mail address is an important example of using the * option for instant text expansion, there are many other times when it comes in handy.

Fixing the “HT”

If you’re a little dyslexic (like me), you may find that you occasionally swap letters when typing on your computer keyboard. Usually your spelling correction program will catch the misstep, but then you have to go back and fix it. Wouldn’t it be better if it was automatically corrected while you’re typing. If done properly you may not even notice that you ever typed the word wrong in the first place.

For example, the letter t and h are commonly found as a letter combination at the beginning of words in the English language (e.g. the, thought, there, their, etc.). It is not uncommon for some people to occasionally hit the h before the t causing a misspelling (or typo).  There is no regular word which starts with ht. We could add all of the th words to the AHK script:

; and so on…

But this would become a lengthy and tedious process since there are a huge number of these words. What we need is one line which will fix all of these conditions on-the-fly:


If ht is accidentally typed at the beginning of a word, the letters are swapped to th without missing a beat. This only works because the number of words (if any) which start with ht (abbreviation for height, high tech, or the first part of http?) are very few and rarely in my vocabulary. (If I use one of those, I will need to fix the problem after the fact.)

Adding this one line resolves the problem for accidentally swapped ht’s at the beginning of words, but I must admit that I’m annoyed by the http problem.  I don’t know that typing ht at the beginning of a th word is much of a problem for me, so I may not  add it to my AutoCorrect script. (You may have other letter combinations which occur at the beginning of words which cause more problems for you.) However, the next example where the problem is in the middle or at the end of a word may be more useful. (I do have a fix for the http problem, but due to it’s slight complexity it is a bit early to introduce it.)

Fixing More Typos with TH

There is a set of words which always contain ht at or near the end. This is the opposite of the th problem at the beginning of some words. These are words where a g precedes the ht (ought, fight, caught, Brighton, etc). There are few a words which follow a g with the th combination (e.g. length, strength) rather than a ht combination, so the key is in the letter preceding the ght. When the ght is preceded by u or i then swapping the ht to th is a common spelling error. How do I know this? I looked it up on the Internet.

In my research I found a site called which will tell you what words contain certain letter combinations. There were none for ugth and igth. But there were plenty for ught and ight. However, these errors all occur in the middle or at the end of words. The usual text replacement will not work. To identify and correct mistakes in the middle of a word the question mark (?) option is used.

When the question mark (?) option with the instant option (*) is added to a Hotstring, the string triggers even when it is inside another string (i.e. the string can be preceded by anything including an alphanumeric character). We keep the asterisk * option in place for immediate triggering which allows the users to continue to type the many variations for the endings. In order to AutoCorrect the many more possible misspellings in our example without adding each individual word to the list as a Hotstring, the following lines are added:


According to the word lookup site referenced above, the first line of code protects against the misspelling of 133 words through the accidental swapping of the ht. The second line adds another 887 word variations to the same AutoCorrect app.

Of course there are times when you want th rather than ht such as in the words strengthen and length.

It’s found that when the g is preceded by the letter n the variation is always th rather than ht. This reverse swapping is another source of common misspellings. It is easily remedied with the following line of code:


This line of code will correct another 45 words.

Note: Before adding a Hotstring line to your AutoHotkey script, it’s important to check that there are no variations of words which include the targeted typo (e.g. nght). You don’t want to autocorrect words from the proper spelling into a misspelling.

To add another 438 misspellings to your list use:


This will find commonly swapped letters in words such as tenth, gazillionths and geosynthetic.

I’m sure that there are many more such examples of common misspellings which can be fixed with similar lines of code. If you find more that are worthy of inclusion in your AutoCorrect file, please let me know. After I check them out, I would like to add the code to my AHK file.

Next time, I’ll look into practical uses of the B0 (no backspace) and C (case insensitive) AutoHotkey Hotstring options.

*         *          *

Find Jack’s AutoHotkey e-Books at

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 )

Connecting to %s