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.
-
1Can 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?– user9290Apr 25, 2012 at 7:33
-
1@WheatWilliams ones like ⌘⌥⌃⇧⎋⏏⌫↑⇡– Daniel ♦Apr 25, 2012 at 19:36
-
4I 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, 2012 at 15:03
7 Answers
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 bindings — this 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 ⌃+⌘+space (in older versions of OS X, the shortcut was ⌥+⌘+T).
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:
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 :)
-
You can also put combining diacritics in the .plist, which opens new options for creating accented characters in general. m10lmac.blogspot.com/2012/04/… Apr 29, 2012 at 15:02
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).
-
At least in Yosemite (possibly before), this UI is found in Language and Region -> Keyboard Preferences -> Input Sources -> (+ Button lower left) -> Other -> Unicode Hex Input. Naturally it'll probably be somewhere else in El Capitan. Sep 27, 2015 at 22:45
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).
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 ⎋
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
- Copy the
.keylayout
file to theKeyboard 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). - Reboot (if you installed the layout system-wide), or log out and log in again (if you installed it for the current user only).
- Enable the new keyboard layout via System Preferences › Language & Text › Input 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:
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
.
SOME IMPORTANT KEYS:
- ⇪ Capslock
- ⇧ Shift
- ⌃ Control(this is the one you are looking for)
- ⌥ Option (Alt, Alternative)
- ⌘ Command
- ␣ Space
- ⏎ Return
- ↩ Return
- ⌫ Delete back
- ⌦ Delete forward
- ⇱ Home
- ↖ Home
- ↸ Home
- ⇲ End
- ↘ End
- ⇞ Pageup
- ⇟ Pagedown
- ↑ Up arrow
- ⇡ Up arrow
- ↓ Down arrow
- ⇣ Down arrow
- ← Left arrow
- ⇠ Left arrow
- → Right arrow
- ⇢ Right arrow
- ⌧ Clear
- ⇭ Numberlock
- ⌤ Enter
- ⏏ Eject
- ⌽ Power
- ⎋ Escape
- ⇥ Tab forward
- ⇤ Tab back