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 want to change one of my keys on my keyboard to a Compose key so I can easily type common accents or characters, e.g.: Compose+e+' -> é.

Is there a setting I can change or a program I can install to add this feature? For instance, I would like to use Caps Lock as Compose.

share|improve this question
1  
If you're on OS X Lion, holding down a letter key will, by default, give you a list of common, accented characters from which you can pick using the number keys. –  Dan J Nov 17 '11 at 0:28
    
Only in certain applications. And only the ones that Apple has chosen for you which tends to be incomplete. –  MikeyB Nov 17 '11 at 0:46
1  
This question (and answer) is also related: superuser.com/questions/202695/real-compose-key-on-mac-os –  elaichi Nov 28 '11 at 9:24
1  
FWIW, Apple's pre-approved list of which accented characters you can choose from can be hacked. –  Daniel Lawson Jun 22 '12 at 13:27
add comment

5 Answers

up vote 7 down vote accepted
+50

I wrote a complete article explaining how to set up a real compose key (ie. Right Option + ' + eé for instance), using a combination of KeyRemap4MacBook and specific Cocoa input rules.

Step 1: choose a Compose key

Choose the Compose key so that it is easily accessible but does not prevent you from doing anything you ordinarily do. I use the Right Option key as my Compose key. I already have a Left Option key so the right one is a bit useless to me. And it somehow matches the position of the Compose key on old Sun keyboards.

That would be Right Option on a Mac keyboard. I recommend that.

Step 2: remap the Compose key

The problem is that the Mac OS X keyboard preferences:

  • do not let you differentiate between Left Option and Right Option keys
  • only let you remap modifier keys to another modifier key (or to nothing)

Fortunately, there is KeyRemap4MacBook that lets you do very low level things with your keyboard. Install it.

We will now remap our compose key to something that the next layer will understand. I chose Shift Control F13 for that. It is very unlikely you will need that key combination.

In the file ~/Library/Application Support/KeyRemap4MacBook/private.xml put the following:

<?xml version="1.0"?>
<root>
  <item>
    <name>Send Shift-Ctrl-F13 for Right Option</name>
    <identifier>private.send_shift_ctrl_f13_for_ropt</identifier>
    <autogen>--KeyToKey-- KeyCode::OPTION_R,
                          KeyCode::F13, ModifierFlag::SHIFT_L
                                      | ModifierFlag::CONTROL_L
    </autogen>
  </item>
</root>

Finally, from the System Preferences, open the KeyRemap4MacBook settings and click on the ReloadXML button. Then activate the new option.

Step 3: create compose bindings

The last step is the creation of the actual bindings. I chose to import the rules from /usr/share/X11/locale/en_US.UTF-8/Compose on my Debian system.

Bob Kåres wrote a script that lets you convert X11 compose rules into Cocoa key bindings.

Either convert a Compose file of your own using Bob’s script, or download my DefaultKeyBinding.dict from the article. Save it in ~/Library/KeyBindings/DefaultKeyBinding.dict.

Be careful: by default Bob’s script uses F13 instead of Shift Ctrl F13 so in DefaultKeyBinding.dict you need to change:

"\UF710"

into:

"^$\UF710"

If for some reason you decided to go for another combination, check out this article by Xah Lee to find out the proper syntax.

share|improve this answer
    
The content of the link looks like a great solution to this problem, but answers on Ask Different need to be more than just a link. It's okay to include a link, but please summarize or excerpt it in the answer. The idea is to make the answer stand alone. –  Daniel Lawson Jun 21 '12 at 19:42
    
@DanielLawson sure, that makes sense; I'll update my answer. –  Sam Hocevar Jun 21 '12 at 20:39
    
There, I copied most of the article. I can do that, since I own it :-) –  Sam Hocevar Jun 21 '12 at 20:48
    
Truly awesome answer; +50 internets. (Seriously, I'm giving this one a bounty as soon as the system lets me) –  Daniel Lawson Jun 22 '12 at 13:18
add comment

A "dead keys" feature similar to what you want already exists by default. To get the letter é, press Option ⌥+e, then e.

After pressing +e, you'll see a ´ character highlighted (it's yellow on my computer). Press any letter that will take that accent mark (this will vary based on your keyboard language, for EN-US it's é, ú, í, ó, and á) and you'll get the accented version of the letter. There are other accents possible: +` gives an agrave accent (```), +e gives an acute accent (´), +u gives a diaeresis/umlaut (¨), +i gives a circumflex accent (ˆ), and +n gives a tilde (˜). Non-US keyboard layouts (in particular Welsh) have more accents and allow more letters for the same accents. The Keyboard Viewer is useful to help figure out what combinations are currently supported on your layout.

If you are on Lion, as @djacobson mentioned, you can hold down some letters to see a variety of accented options for that letter.

share|improve this answer
add comment

Compose key on dedicated keyboard layout

I have written U.S. custom, a keyboard layout that implements the compose key.

On Mac OS X, there are two ways of implementing the compose key: Either with can be implemented either with the Cocoa text system (as already described in Sam Hocevar's most helpful answer) or with a dedicated keyboard layout. Both methods have their pros and cons:

  • A compose key implementation with the Cocoa text system will work independently of the chosen keyboard layout. The Cocoa text system settings in the DefaultKeyBinding.dict file are, by comparison, easily modified.
  • A compose key implementation with a keyboard layout will work all over the OS in any application, not just in Cocoa applications. It can be switched on and off with the UI by selecting another keyboard layout. There is a visual feedback while typing the compose combination (which slightly changes the behaviour).

The installation of the keyboard layout is easy:

  1. Download and open uscustom.2012-08-28.zip.
  2. Move the files UScustom.keylayout and UScustom.icns to either of:
    • /Library/Keyboard Layouts/ (for all users)
    • ~/Library/Keyboard Layouts/ (just for you, no administrator privileges required)
  3. Activate the U.S. custom keyboard layout in the Input Sources tab of the Language & Text Preference Pane, so you can then select it from the input sources menu bar item – its icon shows a U.S. flag with a little C for “custom” or for “compose”: U.S. custom icon.

The compose key of the U.S. custom keyboard layout is mapped to two different keys:

  • There is a compose key at ISO § (that is the surplus key of an ISO keyboard; ISO keyboards are the ones where the return key is shaped like a turned capital letter L).
  • There is another compose key at Shift+Control+F13. This is the same mapping as chosen by Sam Hocevar, so if you want to remap the compose key to you right option key, then you can exactly follow the careful explanations described in his answer.

Assigning compose to capslock

If you want to assign compose to the capslock key (as in the original question), you need Takayama Fumihiko’s PCKeyboardHack in addition to KeyRemap4MacBook:

  1. Install PCKeyboardHack.
  2. Open the PCKeyboardHack preference pane.
  3. Check the Change Caps Lock checkbox.
  4. Doubleclick on the keycode of Change Caps Lock and enter 10 (ISO §).

This works with the U.S. custom keyboard layout compose key. In order to assign the Cocoa text system compose key (as carefully described by Sam Hocevar) to capslock, then you need another step:

With KeyRemap4MacBook, remap the ISO § to Shift+Control+F13 (or whereever your compose key is). To do so, follow the steps carefully explained by Sam Hocevar, but changing the code that is to be placed in ~/Library/Application Support/KeyRemap4MacBook/private.xml thisly:

<?xml version="1.0"?>
<root>
<item>
  <name>Send Shift-Ctrl-F13 for ISO Section</name>
  <identifier>private.send_shift_ctrl_f13_for_iso_section</identifier>
  <autogen>
    --KeyToKey--
    KeyCode::UK_SECTION, ModifierFlag::NONE,
    KeyCode::F13, ModifierFlag::SHIFT_L | ModifierFlag::CONTROL_L
  </autogen>
</item>
</root>
share|improve this answer
add comment

If you want to remap one of your keys, take a look at KeyRemap4MacBook, which is referenced in this SU post. The documentation notes that Caps Lock can be remapped, and custom mappings are also supported.

share|improve this answer
add comment

What's wrong with the default method of accented character input (as of 10.7 Lion)

Just hold down the letter and a list of alternatives will show.

share|improve this answer
1  
This method of input drastically slows down typing speed. Also: apple.stackexchange.com/questions/31487/add-compose-key-to-os-x/… –  MikeyB Aug 29 '12 at 4:06
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.