Searching Data Files and Other Scripting Ploys with Emojis (Secret AutoHotkey Tricks)

Who Knew That You Could Use Emojis in AutoHotkey Scripts Just Like Any Other Computer Character? More Emoji Magic! 😏

Emoji unicornAs I played around with the EmojiMenu.ahk script from my last blog, I tested highlighting an emoji as a search key. I inserted the unicorn emoji (🦄) into a document, highlighted it, then hit CTRL+ALT+E. To my pleasant surprise, it worked! As shown on the right, AutoHotkey searched the EmojiInsert.ahk Hotstring file, located the emoji character for a unicorn, then inserted it into the pop-up menu. (I added the ::!fantasy::🦄 Hotstring—which doesn’t appear in the original EmojiInsert.ahk Hotstring file—after posting the file.)

💡 You can use the EmojiMenu.ahk script to identify any emoji you come across whether on Facebook, in a Windows document, or any other Web page. Any place where you can highlight an emoji (almost everywhere) you can identify the emoji with this AutoHotkey app. I even added the Trim() function to the script allowing users to include the space before and/or after the emoji without affecting the result. (Sometimes selecting only a lone emoji can prove difficult.)

I should have known. Afterall, even though emojis display as images, they actually represent an underlying Unicode. In effect, as long as saved as UTF-8 files and/or scripts, AutoHotkey treats emojis just like any other characters.

Emoji GUI Window

My ultimate test involved building a GUI pop-up window using emojis in the GUI controls, the GUI Labels, and the subroutines, then displaying the emoji name and symbol in a MsgBox:

Gui, Font, s20, Segoe UI Emoji
Gui, Add, Text, g🦄,🦄
Gui, Add, Text, ym g🦃,🦃
Gui, Add, Text, ym g🌵,🌵
Gui, Show

Return

🦄:
  MsgBox, Unicorn 🦄
Return

🌵:
  MsgBox, Cactus 🌵
Return

🦃:
  MsgBox, Turkey 🦃
Return

EmojiGUIClick on any emoji in the GUI window (shown at right) and a subroutine pops up a message box.

This example of a GUI window uses emojis in a number of different ways. First, to get a more detailed emoji in a larger size, I changed the font to Segoe UI Emoji—a better font for displaying emojis—setting it to 20 points:

Gui, Font, s20, Segoe UI Emoji

Emoji MsgBoxNext, I added three GUI text controls using the emojis for both the displayed text (🦄, 🦃, and 🌵) and the gLabel names (g🦄, g🦃, and g🌵). Each subroutine name consists of only the emoji character followed by a colon (🦄:, 🦃:, and 🌵:). The subroutine displays a MsgBox which includes the name of the emoji and the image (shown at right).

If you wanted to turn this script into a child’s educational game, then you can make the image speak by adding to the Label 🦄: subroutine:

ComObjCreate("SAPI.SpVoice")
    .Speak("U IS FOR UNICORN
    . u , , n , , i , , c , , o , , r , , n , , unicorn")

(I word-wrapped the ComObjCreate() function using AutoHotkey line continuation techniques for display purposes only.)

Produce audio using the SoundPlay command as found in the TalkingText.ahk script:

SoundPlay, Sounds/horse.wav

Or, run another multimedia script:

Run, C:\AutoHotkey\PictureSounds.ahk

A major advantage to using emojis includes no longer needing to dig up graphic image files for each of the various icons and pictures. When using independent image files, you must make them separately available to the app, then track them. Not so with emojis. Image files take up a lot of space. Not so with emojis. If Unicode supports the emojis you need for your application, then you add a great deal of flexibility to your scripts by replacing image files with these special characters.

Treat an Emoji Like Any Other Character

AutoHotkey interprets emojis as if merely another character. You can even use emojis in variable names:

var🦄 := "🦃"
MsgBox, %var🦄%

The variable “var🦄” treats the emoji character as another symbol in its name.

Every emoji represents a corresponding Unicode:

code := Ord("🦄") ⇒ 129412
Chr(code) ⇒ 🦄 or Chr(129412) ⇒ 🦄

Since it supports Unicode, use the Ord() function rather than the Asc() function to return the unique emoji Unicode number. You can use the Chr() function to return the emoji character.

You can use emojis in a variety of ways whether mapping your keyboard to type emojis:

::a::✈  ; airplane
::b::🏖  ; beach
::c::🌵  ; cactus

as expressions for searching documents, or in AutoHotkey GUI pop-up windows as shown above. This opens up a new set of possibilities for AutoHotkey scripts—especially in relation to educational/entertainment software.

As I explored these little characters, many ideas (including a couple which I’ve mention here) popped into my head, but I’ll leave the inspiration and development of these scripts to anyone who wants to pursue emoji magic.

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

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 )

w

Connecting to %s