Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I am aware that when I press or on my Mac, I can type a variety of special characters. I also know that I can insert special characters using the character palette. Is there a way to expand the number of special characters I can type while using the keyboard? I am particularly interested in solutions that work in Lion and Mountain Lion.

share|improve this question
1  
Can you give us specific examples of the actual "special characters" you need to use? There are many keyboard layouts available to type many different languages or groups of languages. Which ones are you concerned with? –  Wheat Williams Apr 25 '12 at 7:33
1  
@WheatWilliams ones like ⌘⌥⌃⇧⎋⏏⌫↑⇡ –  Daniel Lawson Apr 25 '12 at 19:36
3  
I like that this is a short, general question that aims at a canonical answer as opposed to a one hit - "How do I get a 😜 (bug eye emoticon) to replace the ® (option R) key" –  bmike Apr 27 '12 at 15:03
add comment

6 Answers

up vote 22 down vote accepted

Custom text entry key bindings

OS X has a very nice text editing system, which you can extend using Key Bindings. You can, for instance:

  • Set up special characters to be entered when you press a certain key command.
  • Insert more than one character at once.
  • Include navigation commands and change the selection.
  • Use multi-stroke key bindingsthis is how I type the ⌃⌥⇧⌘ characters.

To set this up, you just create the file ~/Library/KeyBindings/DefaultKeyBinding.dict and put your customizations there. This article describes the steps in detail.

Here's a list of the default key bindings, and here's Apple's official guide to the text system and key bindings.

Diacritics

If you're just looking to be able to type more diacritics, and you use a U.S. keyboard, consider using the U.S. Extended keyboard layout:

This allows you to type such characters as oòôȯóöơōṯțőo̊ɵỏọţǒŏõǫȏṵṷȍ. You can enable it from the Input Sources section of the Language & Text system preferences.

"Press and hold"

In Lion, you can type many special characters by holding down a similar key on your keyboard:

(It turns out this can be customized, if you're up to the task! All it takes is to edit a plist file.)

Arbitrary text substitutions

If you have specific phrases or characters you'd like to use, you can also set up custom substitutions for them in the Text section of Language & Text preferences:

Character palette

I guess you already know this, but I'll include it for completeness. If you enable "Keyboard & Character Viewer" in the Input Sources section of the Language & Text prefs, you can open the Character Viewer and browse through the entire Unicode character set (and you can also browse characters by category):

This window is easily accessible in most applications with ++T.

share|improve this answer
1  
beautifully comprehensive –  Daniel Lawson Apr 26 '12 at 13:18
1  
In your character palette screenshot, I do not have the options for the bottom 4 sections from Cyrillic downwards. I can see why I might not have the language ones if I do not have them as an input options, but how do you get Musical and Technical symbols? –  stuffe Apr 29 '12 at 11:40
2  
@stuffe You have to go the gear wheel at the top left and select Customize where you can add all kinds of categories. –  Tom Gewecke Apr 29 '12 at 12:51
    
Please remove your link "This article describes the steps in detail", and include the information here or find another source. The source you're using currently won't show the content unless the user shares personally identifiable information with the site and Google. –  Theodore Murdock Mar 10 at 17:54
    
@TheodoreMurdock I can't really reproduce that problem. I don't want to clutter my answer with that information, but if you'd like to find another source, you're welcome to. –  jtbandes Mar 11 at 1:09
show 1 more comment

In addition to simply using the press-and-hold method included in @jtbandes answer, it is also possible to customise the list of options that you are presented with when you hold down a key. In the example below I configured the "Q" key to show a list of special character codes corresponding to the Mac keyboard:

enter image description here

To do this, you need to be comfortable editing a plist file. If you are not sure what a plist file is, this may not be a suitable procedure to follow, just in case you hit problems.

I used TextWranger, but if you have Xcode you can use Plist Editor, or any other tool that can open and read the plist formatted files.

The first step is to navigate to the following location. You may need to make your Library folder available depending on how you choose to get there:

/System/Library/Input Methods/PressAndHold.app/

Right click on this file, and select show package contents, and head on over to ./Contents/Resources/Keyboard-en.plist - choose the keyboard file relevant to your locale if you are using a different keyboard layout.

I took a copy of this file and dragged it over to my desktop for editing. Also, for sanity, take a copy of the entire press-and-hold.app bundle in case you ruin everything. Editing the file, you can see a series of statements that look similar to the following:

<key>Roman-Accent-a</key>
<dict>
    <key>Direction</key>
    <string>right</string>
    <key>Keycaps</key>
    <string>a b á â ä æ ã å ā</string>
    <key>Strings</key>
    <string>a b á â ä æ ã å ā</string>
</dict>

In the example above, when holding down the lower case 'a' key, you will get the following alternatives. I included 'b' in the list also. After making the changes and saving the file, I dragged the file back into the press-and-hold bundle into the correct place, and authorised as administrator to allow the copy to complete. To make this available, you need to log out/in to reload the plist. Now just press and hold the key(s) you modified, to see your new list.

You can put anything you like in the alternatives list, just leave a space between each one, and don't bother going above 9 entries if you are a keyboard shortcut junkie, as you cannot select one of the alternatives by typing '10' without just getting '1' instead, even though the numbers above 9 still get listed... Note that as per the above image, you can include unicode characters, emoji, and indeed anything that you can find in the special character palette that is also included in @jtbandes answer

    <key>Roman-Accent-Q</key>
<dict>
    <key>Direction</key>
    <string>right</string>
    <key>Keycaps</key>
    <string>Q ⌃ ⌥ ⇧ ⌘ ⎋ ⏏ ⌫ ↑ ⇡ ↖ ⇞ ⇥</string>
    <key>Strings</key>
    <string>Q ⌃ ⌥ ⇧ ⌘ ⎋ ⏏ ⌫ ↑ ⇡ ↖ ⇞ ⇥</string>
</dict>

For preference, rather than ammend existing entries, I simply tested keys for ones that had no existing alternatives and made a fresh statement in the plist file for those keys as per above. But be careful to check for duplicate statements for the same letter, as likely only 1 will work. Try to keep them in alphabetical order for sanity.

Keys q/Q/z/Z are good options for fiddling with, having no pre-existing alternatives for that particular locale/keyboard that I used. This can give you up to 36 'slots' for creating custom shortcuts to unusual characters. You can have a set of Emoji, a set of Keyboard characters etc etc on any key you like. Likely other characters are also currently free of alternatives, and perhaps using a non-alphanumerix key like ` or @ or ¬ or ~ would be a good choice if you are filling the alternatives list with more non alphanumeric characters, but I don't know currently how you would identify them in the plist - would <key>Roman-Accent-~</key> work? I have no idea, I didn't test that.

Note, take a copy of the plist somewhere, I have no idea if this will be overwritten on subsequent OS updates etc, and it would be a pain to remember what you did and repeat it next month when 10.7.4 is out etc.

It's possible that you can replace with more than a single character also. I didn't try this either. But is anyone fancies adding this <kbd></kbd> to the k assignment, I'd be interested to see what happens :)

share|improve this answer
2  
This answer needs more upvotes! That custom list is awesome. –  Ian C. Apr 27 '12 at 13:43
    
I was wondering how you did this before! Thanks for posting this! Also, I was wondering if you could post a link to the .plist file that you used in the example picture above? Thanks! –  anon173 Apr 27 '12 at 22:06
    
@ruddfawcett I pasted my stanza straight into the answer, you should be able to copy the whole block and drop it into your plist. –  stuffe Apr 29 '12 at 11:36
    
@stuffe Cool, thanks. I totally missed that. –  anon173 Apr 29 '12 at 12:15
    
You can also put combining diacritics in the .plist, which opens new options for creating accented characters in general. m10lmac.blogspot.com/2012/04/… –  Tom Gewecke Apr 29 '12 at 15:02
add comment

If you enable the "Unicode Hex Input" keyboard, you can enter any special character, knowing their Unicode code.

For example, if I press , and I click on 2, 2, 0, and 0, while keeping pressed, I get ∀ (the FOR ALL Unicode character).

screenshot

share|improve this answer
add comment

You can design a custom keyboard layout, which will appear in the input source list next to U.S. and Dvorak and Turkish and all that. You can arbitrarily change what character(s) are produced for any key with any combination of modifiers, and multi-character combinations (which in this context are known as “dead keys”, such as Optione which makes acute accents, but can be much more general than that).

Ukelele is a free program for editing keyboard layouts. I use a keyboard layout of my own design, which notably adds dead keys for typing mathematical symbols and Greek letters (without switching to a Greek keyboard layout).

share|improve this answer
add comment

I incorporated Stuffe's excellent pop-up key solution into my own workflow (adjusted to include the keys I care about)and am extremely pleased with it.

Seeking similar functionality on iOS, I also created a set of TextExpander snippets which I can access from my iOS devices or any Mac to which I sync my TextExpander settings. (I currently use DropBox to do so.) This is arguably faster than editing the plist file when I first "take control" of a new machine, and is less intrusive on Macs that I'm just borrowing.

Below is my list of snippet shortcuts followed by the character (or entity) that it expands to:

,,via   ᔥ
,,ht    ↬
,,kb   <kbd>%|</kbd>
,,cmd   ⌘
,,alt   ⌥
,,opt   ⌥
,,ctl   ⌃
,,esc   ⎋
share|improve this answer
add comment

There are some important gotchas with the other solutions posted here. I’ll explain them, and offer an alternate solution that avoids these issues.

For one, symbol and text substitution entries only work in Cocoa apps. If you want a truly system-wide solution that works in all applications, this is not an option.

Also, apps like KeyRemap4MacBook are great, but relying on them means you have to keep the app running in the background all the time, which may not be what you want.

Custom keyboard layouts to the rescue

Luckily, remapping keys can be done in a way that will work for any type of application, and without any additional software!

Mac OS X has supported .keylayout files since version 10.2 (Jaguar). You can create your own keyboard layout, or rather, tweak the default one you’re using right now. Simply remap a keyboard combination you never use (for me, there are plenty of those) to the ² and ³ symbols, and that’s it.

In my custom QWERTY keyboard layout, I can simply press + + 2 to enter ², and + + 3 to enter 3. (My custom AZERTY layout has these mappings, too.)

How to create a custom keyboard layout

To create new keyboard layouts or modify existing ones, I’d recommend Ukelele.app. It has an option to create a new keyboard layout based on the one that’s currently in use.

After you’ve created your custom layout, there’s no need for the application anymore — you certainly don’t need to keep it running in the background.

How to install a custom keyboard layout

  1. Copy the .keylayout file to the Keyboard Layouts folder within ~/Library (if you want to install it only for the current user) or /Library (if you want to install the layout system-wide).
  2. Reboot (if you installed the layout system-wide), or log out and log in again (if you installed it for the current user only).
  3. Enable the new keyboard layout via System PreferencesLanguage & TextInput Sources.

How to make a custom keyboard layout the system default

Optionally, you could make the custom keyboard layout the system default by running the Setup Assistant with root privileges. This way, it will be used for the login screen, and any new user accounts you create will default to this layout as well. Note that this can only be done for keyboard layouts in /Library/Keyboard Layouts (i.e., layouts that have been installed system-wide).

sudo rm /var/db/.AppleSetupDone; sudo "/System/Library/CoreServices/Setup Assistant.app/Contents/MacOS/Setup Assistant"

You will have to create a new user account in order to complete the Setup Assistant — but don’t worry, you can delete the new account afterwards.

Adding a custom icon to the keyboard layout

OS X will use the following default icon for your custom keyboard layout:

Screenshot

This icon will show up in the preference pane, and in the “Input menu” in the menu bar.

To replace this with your own icon, create a 16×16px image, and save it in .icns format in the same directory as the keyboard layout itself, using the same file name (only the extension differs). For example, my custom QWERTY layout is named qwerty.keylayout, so if I wanted to use a custom icon, it’d have to be named qwerty.icns.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.