Add Currency (and Other) Symbols with AutoHotkey Hotstring Menus (Part 6, Beginning Hotstrings)

Use AutoHotKey Hotstring Menus to Add Currency Symbols to Any Windows Program or on the Web

*          *          *

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.

*          *          *

In Chapter Twenty-four of the e-book Digging Deeper into AutoHotkey, I discuss using Hotstrings to insert special characters:

::(c)::©
::(r)::®
::(tm)::™
::cents*::¢
::pounds*::£
::yen*::¥
::plusminus::±

Each line of code represents one Hotstring which inserts one symbol. Typing the activating string followed by a space or other punctuation inserts the symbol as a replacement.

Comment: When I do an update to Digging Deeper I plan to make changes to the above Hotstrings—which I’ve already included in my AutoCorrect file. I will add the * option between the first two colons. This causes activation the instant the last character is hit—not waiting for a space or other punctuation. The effect also eliminates the need for removing any extra, unwanted spaces. Plus, I will use the ? option for those symbols which normally appear at the end of a string. The cent sign ¢ and other symbols which appear at the end of a number or word need the ? option. Without it the Hotstring will not activate.

The following is now part of my AutoCorrect file—although I may switch to the Hotstring menu options discussed in this blog:

:*?:cent*::¢
:*:pound*::£
:*:yen*::¥
:*:euro*::€
:*?:+-::±
:*?:(c)::©
:*?:(r)::®
:*?:(tm)::™
:*?:deg*::°
CharMap
Windows CharMap makes it easy to select and copy special characters and symbols. To open Run→CharMap.

These lines of Hotstring code save the looking up of each one of these symbols in Windows CharMap (shown at right and discussed in Chapter One, “Add Currency Symbols and More to Your Keyboard with Hotkeys!” of the Digging Deeper book), then adding the symbols individually. The only problem with using one Hotstring for each symbol is remembering all of the activation Hotstrings. Wouldn’t it be easier to use just one or two Hotstrings and select the appropriate symbol from a menu of those characters you use most?

Tip: If you’re having trouble finding a particular symbol for inclusion in your Hotstring menu, you can open Windows CharMap (shown above) with Run (WIN+R), type in charmap (Run→CharMap), then click OK.

In this blog, the Hotstring pop-up menu function and MenuAction: Label subroutine from the last blog are reused making the building of menus for inserting special characters easy. While we need different Hotstring options to accommodate the special requirements for symbol placement, nothing changes in the TextMenu() function:

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

or the MenuAction: Label subroutine:

MenuAction:
  SendInput %A_ThisMenuItem%{raw}%A_EndChar%
Return

First, let’s look at inserting currency symbols by creating a Hotstring menu with the above function and subroutine:

::cur::
  TextMenu("¢,£,€,¥")
Return

The currency symbols were merely cut-and-pasted from another source (CharMap or anywhere else they can be found).

(Remember both the function TextMenu() and the label subroutine MenuAction: must appear in the AutoHotKey script for this to work.)

CurrencyMenuWhen the activation string cur is typed (followed by a space or punctuation) the currency symbol menu pops up (as shown at right). But there are a few problems with this approach.

First, as mentioned above, the activating character (A_EndChar) is automatically added to the end of the replacement text in the MenuAction: subroutine. This is easily remedied by inserting the * option:

:*:cur::
  TextMenu("¢,£,€,¥")
Return

ComputorEdge AutoHotkey E-BooksThis works because the variable A_EndChar is blank whenever the * option is used.

The second problem occurs when the activating string cur appears at the end of a number—as is the case when inserting the cent sign ¢ after a number. This doesn’t work because cur is considered part of the previous string and won’t trigger. The only way to force it to activate is by using the ? option. However, this causes the Hotstring to fire at the end or inside of any word which contains cur, such as, occur or recurring.

It is best to employ an activation Hotstring which is not likely to appear in any word, such as any string followed by the TAB character (`t). (TAB is designated by the letter t escaped with the backtick mark—`t.):

:*?:c`t::
  TextMenu("¢,£,€,¥")
Return

Now, any of the listed currency symbols can be added anywhere in the text (before the number, after number, or the middle of the number) by merely typing the letter c followed by the TAB key. The menu pops up waiting for your selection. No spaces or punctuation are needed for triggering the menu nor added after the replacement.

Adding Fractions to a Menu

You could add all of the symbols to the menu above, but it might make more sense to group them according to use. You might set up fractions to be inserted with the letter f (for fractions) followed by TAB.

:*?:f`t::
  TextMenu("¼,½,¾")
Return

Adding Math Symbols to a Menu

If you often use math symbols, then possibly the letter m (for math) followed by TAB could pop-up a menu:

:*?:m`t::
  TextMenu("±,÷,×,¹,²,³,ƒ,∫,∑,∞,≈,≠")
Return

There may be times when you would like to see possible alternative words pop-up whenever you use the same old plain vanilla word—even though it’s spelled correctly. This helps prevent your writing from becoming stale from redundant use of the same word. Next time, we’ll discuss how to make AutoHotKey synonym pop-up menus.

We could use the current menu function, however, that function is set up for immediate deletion of the old text—even if you want to keep it. If you hit ESC or click off the menu, you lose the original text. Next time, we take a look at how to prevent the deletion of the typed text when no selection is made on the synonym Hotstring menu.

*         *          *

Find Jack’s AutoHotkey e-Books at ComputorEdgeBooks.com.

Advertisements

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 )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s