The Duality of Curly Brackets in Hotstrings (Beginning AutoHotkey Tips)

Curly Brackets {…} in Hotstrings Both Insert Special Features and Neuter Hotkey Modifying Characters—When Properly Used, They Add Flexibility to AutoHotkey Hotstrings

Sometimes you want to do more than simple text replacement with your AutoHotkey Hotstrings. The key to adding those special features lies with embedding either manual keys within curly brackets (i.e. {Left 5}) or adding Hotkey action directly (without curly brackets) such as CTRL+I (^i for italics) or CTRL+B (^b for bold). The fact that the curly brackets {…} behave in two different manners can cause confusion.

How Curly Brackets {…} Work

You use curly brackets {…} in your Hotstrings to:

  1. Beginning AutoHotkey Hotstrings 200pxConvert the Hotkey modifiers (^ for the CTRL key, # for the Windows key , ! for ALT key, and + for the Shift key) into raw text eliminating their magical shortcut powers. Plus, to appear in the replacement string as raw text, the curly brackets themselves need demagnetizing (i.e. {{} and {}}).
  2. Add special keyboard action available through the list of key names used with the Send command (e.g. {Enter} for a new line, {Left} to move the cursor left, {Right} to move the cursor right, etc).

When used properly, you can create numerous Hotstring tricks with one-line of code. (For more information on AutoHotkey Hotstrings, see my book Beginning AutoHotkey Hotstrings.)

Curly Brackets to Send Raw Code

In “Dealing with Hash Marks (#) in Hotstrings (AutoHotkey Quick Tip)“, I used the jump-to-in-page hash mark # found in many Web URLs to demonstrate how to deactivate all special characters in a Hotstring. In the following example:


the Hotstring action removes the # sign.

(The above code and the Hotstrings below use line continuation techniques to wrap lines of code for display purposes.)

Unfortunately, since the # character represents the Windows key  Hotkey modifier, it activates and disappears from the replacement text rendering the URL inoperable:


Rather than setting the entire line to the raw text mode (T or R option), merely enclose the # within curly brackets:


This solves the jump-to problem. Plus, when adding key names inside curly brackets (e.g. {enter}), you can make your Hotstrings even more flexible.

Add Special Features to Hotstrings

Since the curly bracket ({…}) key names work in Hotstrings as well as they do with the Send command, you can create a number of Hotstrings useful for both writing and programming. For example, whenever you insert an open parenthesis, it inevitably terminates with a close parenthesis. By adding the code {left} to a single digit Hotstring you can both close the set of parentheses and set up the cursor for adding text or code.

For example, this Hotstring consists of a single open parenthesis replaced with the set of parentheses followed by moving the cursor left one space to inside the set:


The * option executes the Hotstring the instant you press the open parenthesis key. You can do the same with the curly brackets except you must deactivate their normal function by surrounding each with an additional set of curly brackets:


The following example taken from the online documentation shows how to set up Hotstrings for inserting HTML tags ready for entering text between the opening and closing tags:

:*b0:<em>::</em>{left 5}

Note: the numeric value in the {left 5} parameter must match the number of left arrow presses needed to place the cursor between the two HTML tags.

Multi-Line Hotstrings

The online documentation demonstrates how to insert multi-line replacement text by using continuation parentheses. But, by using Hotkey combinations with key names, you can often include multi-line results in a one-line Hotstrings:

:*:jks::Jack Dunning+{enter}1234 Main Street+{enter}Anytown, USA

This Hotstring uses the shortcut combination SHIFT+ENTER (+{enter}). Using {enter} alone inserts double-spacing in WordPress and many other word processing programs while SHIFT+ENTER single-spaces the lines:

Jack Dunning
1234 Main Street
Anytown, USA

This also works in most text editors since the text editor ignores the + sign and executes the {return}. Adjust the Hotstring as necessary for the shortcuts in your word processing software.

Tip: Pick an unlikely set of consonants (e.g. jks for Jack’s) as your Hotstring combination. If you use a non-naturally occurring activating string, you’ll encounter fewer conflicts with real words.

Adding Multi-Line Text to Forms

Suppose we want to fill in a form with the above name and address? With a couple of modifications, you can write a Hotstring which loads the fields of an AutoHotkey GUI pop-up, then clicks the submit button:

:*:jks::Jack Dunning{tab}1234 Main Street{tab}Anytown
     , USA{click 35 125}

Gui Hotstring Tab

In AutoHotkey GUI forms, the TAB key moves the cursor focus to the next field, then selecting the entire text (if any). By including the {tab} key name, AutoHotkey jumps to the next GUI control before inserting the additional text. Then AutoHotkey Submits the form by pressing the left mouse button ({click 35 125}).

Note: The {click x y} parameter uses coordinates (x,y) relative to the upper left-hand corner of the GUI window. You can determine the location of a spot in the middle of the button using Window Spy. (Right-click on the AutoHotkey script icon in the Windows System Tray Notification Area and select Window Spy from the context menu.)

Or for an easier solution, add another {tab} and include the {enter} key name to activate the submit button:

:*:jks::Jack Dunning{tab}1234 Main Street{tab}Anytown
     , USA{tab}{enter}

When properly formatted for the page, this type of Hotstring also works for Web forms since the TAB character jumps to the next field in most browsers. If the activating button lies at a remote location on the Web form, then you may find using the {click x y} key name less confusing than entering too many {tab} keys. Often, you will find this Hotstring trick quicker and easier than using Hotkeys with the Send command.

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 )

Google photo

You are commenting using your Google 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