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 for 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
The 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:
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.
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.
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:
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
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:
- The sheer number and variation in the commands seriously complicate the problem.
- 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.)
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.)
4 thoughts on “Adding Italics to Hotstrings in Word Processing Software (AutoHotkey Quick Tip)”
[…] discussed in “Adding Italics to Hotstrings in Word Processing Software (AutoHotkey Quick Tip)“, any time you include a Hotkey Modifier Symbol in a Hotstring, AutoHotkey interprets it as […]
[…] Adding Italics to Hotstrings in Word Processing Software (AutoHotkey Quick Tip) […]
Just stumbled on this blog … love it. I’m running into a “snag” with the implementation you suggest above.
Ordinarily, auto-replace hotstrings preserve case … sort of. If you type the trigger in all caps, the replacement will be in all caps. If you type only the first letter in caps, then only the first letter will be in caps, etc.
The problem comes when you use a hotstring like “::foobar::^ifoobar^i” and type “Foobar. You would *expect* it to type “Foobar” in italics, but it doesn’t. It types “foobar” in all lower case. I suspect this is because it’s trying to capitalize the first letter but, in this case, the first “letter” in your replacement is actually the control character “^”.
I’m trying to find a way around this, but thought I’d point it out. Heck – maybe it’s just me.
You need to make the Hotstrings case-sensitive with the C option, then write one for each case:
Plus, you may need to use the T option for the Raw text mode depending upon where you’re using them.