Adding Italics to Hotstrings in Word Processing Software (AutoHotkey Quick Tip)

If You Work with a Word Processing Program (Local or Web-Based) Which Supports Control Characters for Special Formatting, Then, Possibly, You Can Add Auto-Italics (or Bold, Underline, Etc.) to Your Autohotkey Hotstrings

A little while back, I wrote the blog “Italicize Your Hotstring Replacements with this Input Command Ploy (AutoHotkey Tip)” which demonstrated tricks for adding special features robotaicartoonfor both the Input command and Hotstrings. While clever solutions (possibly too clever), I now realized that in many programs (and Web apps), there might exist a much easier solution—a “duh” moment.

Adding Italics to Hotstrings—the Simple Method

Usually, when I add individual formatting to text, I highlight the target string and either click the appropriate button or use a control key combination. For example, WordPress offers both an italics button in the editing toolbar and an italics control key code (CTRL+I). This works well but for certain styles (i.e. italics, bold, underline, and strike-through), you can also toggle the feature on and off using the same control key combination (CTRL+I, CTRL+B, CTRL+U, ALT+SHIFT+D, respectively in the WordPress editor). That means you can hit CTRL+I to start italics, then hit it again to return to normal type. This makes italicizing or adding certain other styles to Hotstrings much easier. (For an introduction to Hotstrings, see the book Beginning AutoHotkey Hotstrings.)

Italicizing AutoHotkey Command Names in Hotstrings

Beginning AutoHotkey Hotstrings 200pxThe other day I started working on a blog which discusses saving Hotstrings using the FileSelectFile command. (In print, I emphasize with italics the names of AutoHotkey commands.) As I mulled over the idea of creating instant Hotstrings for inserting “FileSelectFile command”, the idea of including the italics in the original input reoccurred. While the method I used in the previously referenced blog works, it’s too convoluted to implement for all the AutoHotkey commands.

I thought about adding tags to the Hotstrings—as I might when working with HTML code:

::fsf::FileSelectFile command

however, in WordPress, this merely displays the tags () as part of the text. To make this work, I need to directly edit the HTML page. Too awkward.

Lightbulb Small Then the light turned on! Many word processing programs allow you to toggle certain key styles on and off while typing. Although quite a few text formats require preselection of words before implementing the style, a few common modes toggle on/off using workaday control codes. Since AutoHotkey by default interprets and sends the Hotkey modifying symbols (CTRL  (^), ALT (!), SHIFT (+), and/or the WIN (#)) included in Hotstring replacement text, you can activate special shortcuts by embedding them directly into your Hotstrings.

I tested this technique using the InstantHotstring.ahk script. It worked like a charm.

instanthotstring italicize
Control codes do not work in every editing window. While this Hotstring will italicize the word FileSelectFile in WordPress, in text editors, it merely inserts TAB characters (or nothing) as shown in the Hotstring Test Pad in the image above.

The Hotstring depicted turns on italics (^i) before inserting the command name, turns off the italics (^i) before inserting the word “command”, then appends the EndChar:

::fsf::^iFileSelectFile^i command

In most word processing apps, this Hotstring yields “FileSelectFile command”—after typing “fsf” followed by a space or punctuation.

This italicizing technique only works in word processors which recognize these few toggle codes—including the programs I tested (WordPress, Wordpad, LibreOffice Write, and Sigil EPUB editor). Text editors such as NotePad and Notepad++ do not respond to the control codes. Notepad substituted the TAB character in the same manner as the InstantHotstring.ahk app shown above.

I wrote this Hotstring to test the four toggling features available in WordPress:

::ibus::^iitalics^i ^bbold^b ^uunderline^u !+dstrikethrough!+d

This Hotstring toggles the four shortcuts which work in WordPress. While italics (^i), bold (^b), and underline (^u) proved more universal in most word processors, for the programs I tested, strikethrough (!+d) only worked for the online WordPress editor:

italics bold underline strikethrough

Note: I needed to suspend my regular Hotkeys since, normally, I use CTRL+U to change selected letter case to all caps.

Adding the Special Feature Hotstrings to an AutoHotkey File

I could probably write a Regular Expression to create these Hotstrings from a list of AutoHotkey commands. I don’t plan to approach the task in that manner for a couple of reasons:

  1. The sheer number and variation in the commands seriously complicate the problem.
  2. Even if I manage to create that number of Hotstrings, remembering that many activating strings presents a formidable challenge.

Alternately, I plan to use the InstantHotstring.ahk script to create the Hotstrings as I require them. That way I can start with a fairly short list and quickly add commands, such as the MsgBox command, as needed. I’ll learn the activating Hotstrings as I work with them. (I plan to use the major consonant letters in each command name such as “fsf” for “FileSelectFile command” as activating strings. This should make each string easier to remember—although I’ll need to watch for conflicts.)

Tip: By using the InstantHotstring.ahk script to load the AutoHotkey command Hotstrings, I can quickly remind myself of the activating codes by checking the DropDownList of active Hotstrings.

I’ll save the Hotstrings to an AutoHotkey command Hotstring file (cleverly named “AutoHotkey Commands.ahk”)—only loading and activating the Hotstrings in the InstantHotstring.ahk app when needed. Each time I create new Hotstrings for future blogs, I’ll save the entire set to the same file name.

I also plan to add the URLs for each command by adding an “l” (for link) to the end of the matching command activating string. (I encountered some problems with including URLs in the InstantHotstring.ahk app. I plan “Solving the Problems of Adding URLs to the InstantHotstring.ahk App” as a future blog.)

This approach to building specialized Hotstring collections which you can activate or deactivate at-will offers a solution for anyone attempting to build their own shorthand system. Plus, adding the control codes which work in your software for special formatting will save you even more time.

Most text style options (color, hyperlinks, etc.) do not provide easy on/off shortcuts, in which case, you may find excellent uses for the brilliant(?) solutions I provided in that original blog. But if the formatting toggle codes you need exist in your software, use this simpler, more direct Hotstring approach.

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.)

jack

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.)

Advertisements

One thought on “Adding Italics to Hotstrings in Word Processing Software (AutoHotkey Quick Tip)

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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