AutoHotkey Tip of the Week: Hotstring Menu Techniques for Inserting Symbols and Emojis

Place Special Characters and Emojis in Hotstring Menus to Make Them Easy to Find for Inserting into Documents, Plus Sample Hotstring Special Character Menus

MenuEmoji
Hotstring Menu

In my last blog, “AutoHotkey Hotstring Menus for Text Replacement Options“, I expanded upon the Hotstring menu technique discussed in Chapters Eight and Nine of my book Beginning AutoHotkey Hotstrings. While the menus work great, I noticed that, in many instances, the standard built-in Windows menu objects do not always make it easy to distinguish various characters. For example, when I placed a mix of symbols and emojis in a menu, it produced ambiguous results:

:x*?:b``::TextMenu("🦄,🐀,🐁,🐂,🐃,®,❓,❔")

The characters appear small in the menu (shown at right above)—often without clearly defined differences.

In the menu, the rat (🐀) and mouse (🐁) seem very similar—as do the ox (🐂) and the water buffalo (🐃). The two question marks at the end of the menu look identical, although, the first emoji inserts the punctuation mark in red (❓) while the second adds a white question mark (❔). We need another method for discriminating between the menu options.

Beginning AutoHotkey Hotstrings 200px

Light Bulb!

AutoHotkey offers no easy fix for independently changing the text size of the built-in Windows menu object. You can adjust the appearance of those characters in the Windows System setup (use System Display Settings to change text size), but any new setting affects the text size of virtually every app and tool in Windows—often making the change undesirable. Even then, increasing the size of the menu items won’t fix the emoji question mark problem discussed above.

Adding Tags to AutoHotkey Menu Items

MenuEmojiTags

You might find that adding descriptive tags to the menu items offers the easiest way to differentiate the various characters. To do this, the script must:

  1. Allow the addition of almost any text to the menu item as a comment, but…
  2. Not include the distinguishing text when inserting the special character(s) after menu selection.

I accomplished this by preceding the tag text with a vertical bar (|) as a delimiter and adding a couple of lines of code:

:x*?:b``::TextMenu("🦄 | Unicorn,🐀 | Rat
          ,🐁 | Mouse,🐂 | Ox,🐃 | Water Buffalo
          ,🐄 | Cow,❓ | Red,❔ | White")

(The above snippet uses line continuation techniques to wrap the code lines for display purposes. )

While this makes each menu item easier to identify, AutoHotkey must prevent the text from appearing in the inserted text by adding code to the MenuAction subroutine:

MenuAction:
  InsertText := StrSplit(A_ThisMenuItem, "|")
  TextOut := StrReplace(RTrim(InsertText[1]), "&")
  SendInput {raw}%TextOut%%A_EndChar%
Return

The StrSplit() function parses the menu item (A_ThisMenuItem) using the vertical bar (|) as a delimiter—eliminating the descriptive text from the first array item (InsertText[1]).  I used the RTrim() function to remove any spaces added for cosmetic reasons between the special character and the delimiting vertical bar.

Bonus Tip: You can add a single-key shortcut to your menu item (e.g. &1, &2, &3, etc) without affecting output by placing it anywhere after the delimiting vertical bar (|):

:x*?:b``::TextMenu("🦄 | Unicorn &1,🐀 | Rat &2
          ,🐁 | Mouse &3,🐂 | Ox &4,🐃 | Water Buffalo &5
          ,🐄 | Cow &6,❓ | Red &7,❔ | White &8")

Save a Keyboard Character

If you rather not consume a keyboard character, then substitute a non-keyboard symbol such as the broken bar (¦) as the delimiter in place of the solid vertical bar (|):

:x*?:b``::TextMenu("🦄 ¦ Unicorn,🐀 ¦ Rat
          ,🐁 ¦ Mouse,🐂 ¦ Ox,🐃 ¦ Water Buffalo
          ,🐄 ¦ Cow,❓ ¦ Red,❔ ¦ White")

Then replace the same character in the MenuAction subroutine:

MenuAction:
  InsertText := StrSplit(A_ThisMenuItem, "¦")
  TextOut := StrReplace(RTrim(InsertText[1]), "&")
  SendInput {raw}%TextOut%%A_EndChar%
Return

This frees up the keyboard character (|) for other purposes.

Current Form of the Hotstring Menu Function and Subroutine

Add the TextMenu(TextOptions) function and MenuAction subroutine to your script and call the TextMenu() function using Hotstring Execute Option (x) in the format shown in the examples above (and below):

TextMenu(TextOptions)
{
  StringSplit, MenuItems, TextOptions , `,
  Loop %MenuItems0%
  {
    Item := MenuItems%A_Index%
    Menu, MyMenu, add, %Item%, MenuAction
  }
  Menu, MyMenu, Show
  Menu, MyMenu, DeleteAll
}

MenuAction:
  InsertText := StrSplit(A_ThisMenuItem, "|")
  TextOut := StrReplace(RTrim(InsertText[1]), "&")
  SendInput {raw}%TextOut%%A_EndChar%
Return

Note: I used the deprecated StringSplit command in the TextMenu(TextOptions) function while I switched to the preferred StrSplit() function in the MenuAction subroutine. The command creates a pseudo-array (i.e. MenuItems%A_Index%) while the function creates a simple array (i.e. InsertText[1]). I plan to switch the first StringSplit command to an appropriate StrSplit() function before I post this Hotstring menu technique on the free scripts page (i.e. MenuItems%A_Index% ⇒ MenuItems[A_Index]).

Reposition the Hotstring Menu Location

Bonus Tip: If you want the menu to pop-up at the text input cursor position rather than the mouse cursor location, replace:

Menu, MyMenu, Show

with:

Menu, MyMenu, Show ,%A_CaretX%,%A_CaretY%

More Special Character Hotstring Menu Examples

The following examples demonstrate how to add a Hotstring menu for various types of symbols and characters.

International Currency

MenuMoneyPreviously, I used a separate Hotstring for each currency symbol:

:*?:cent*::¢
:*:pound*::£
:*:yen*::¥
:*:euro*::€

In this example, the dollar sign ($) followed by the backtick (`) instantly pops up a currency symbol menu:

:x*?:$``::TextMenu("¢,£,¥,€")

With this Hotstring menu, I save both keystrokes and Hotstring code lines.

Numeric Fractions

MenuFractionsThis TextMenu(TextOptions) function combines the few ANSI fraction characters with the extended Unicode fraction symbols to create and a fractions selection menu:

:x*?:f``::TextMenu("⅒,⅑,⅛,⅐,⅙,⅕,¼,⅓,⅜,⅖,½,⅗,⅝,⅔,¾,⅘,⅚,⅞")

Note: Adjusting the system-wide Windows setting for text size may display the standard and emoji characters differently (e.g. ¼, ⅐, and ⅞).

Trademarks, Degrees, and Punctuation

MenuMarks

MenuMarks2

To get a better look at the effects of changing the Windows System text size, I increased the system font size of the text in the first menu on the right. The next menu on the right shows its appearance when set at the default text size.

The TextMenu function used for the test includes a mix of symbols and punctuation:

:x*?:s``::TextMenu("©,®,™,°,•,·,…,¶")

While the menu looked better with the enlarged font size, the text in some of the other Windows apps appeared freakish.

Mathematical Symbols

MenuMath

I previously used a number of Hotstring definitions for inserting math symbols, but I could never remember all of them.  This menu resolved the confusion:

:x*?:m``::TextMenu("±,×,÷,≈,≅,∑,ƒ,¹,²,³")

Using the tagging technique above, I can add names:

:x*?:m``::TextMenu("± | Plus or Minus,× | Times
                   ,÷ | Divide,≈ | Almost equal to
                   ,≅ | Approximately equal to
                   ,∑ | Summation,ƒ | Function of
                   ,¹ | Power of 1,² | Power of 2
                   ,³ | Power for 3")

Okay, I don’t need x for multiply because it appears on the keyboard, but the division sign ÷ would feel lonely without it.

Cursor Arrows

MenuArrows

I primarily use the double right arrow ⇒ to prove a point:

:x*?:a``::TextMenu("⇐,⇔,⇒,⇑,⇓")

Now, I don’t need to search for it in a special character chart.

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

 

 

 

3 thoughts on “AutoHotkey Tip of the Week: Hotstring Menu Techniques for Inserting Symbols and Emojis

  1. […] Note: While adding more parameters to the function does make it more flexible, it does not necessarily make it simpler. For that reason, I continue to include the original HotstringMenu() function in the master script and changed the name of the variadic form of the function to HotstringMenuV(). Some people may find the original function easier to use (as described in the blogs “AutoHotkey Hotstring Menus for Text Replacement Options” and “Hotstring Menu Techniques for Inserting Symbols and Emojis“). […]

    Like

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