Saturday, May 16, 2009

Entering Special Keyboard Symbols on a Mac

Keyboard keys like Tab, Control and Shift are occasionally represented in text using symbols. For example, Tab is represented as an arrow pointing right with vertical bar at its head. Each of these symbols is represented by a Unicode code point. Therefore, if you know the code point, and how to enter code points into your editors, you can make use of these symbols.

The first way to enter these symbols relies on you creating a HTML document. Code points can be entered as HTML entities in the form &#x<code point>;. This assumes the <code point> in its hexadecimal representation. The code point for the Tab symbol described above is 21E5 and looks like ⇥. Of course, whether you see the symbol correctly depends on your viewer's ability to interpret the HTML entity and display the corresponding symbol.

If you are not writing a HTML document, you can still insert these symbols (if your editor supports doing so). On a Mac this can be done via the following process:

1. Open System Preferences
2. Select International
3. Select Input Menu
4. Scroll to the bottom and check "Unicode Hex Input"

You should now have a little "U+" icon in your menu bar at the top right. With this enabled you can now enter symbols by typing the code point while holding the Alt/Option key.

That is pretty much it. I think a similar process is used on Windows.

Here is a list of code points for some of the keys on a Mac OS X keyboard.

KeyCode PointSymbol
Control2303
Alt/Option2325
Shift21E7
Command2318
Tab21E5
Backtab21E4
Return21A9
Enter2305
Delete2326
Backspace232B
Escape238B
Left Arrow2190
Right Arrow2192
Up Arrow2191
Down Arrow2193


TextMate's HTML bundle has tab triggered snippets for each of these symbols. To enter the Tab entity just type tab⇥.

1 comments:

Anthony said...

Sometime between when I wrote this post and now where I am running Mac OS X 10.6.4, the menu items for enabling Unicode Hex Input has changed. Here is the new sequence.

1. Open System Preferences
2. Select Language & Text
3. Select Input Sources
4. Scroll to the bottom and check "Unicode Hex Input".