Setting up a real Compose key on Mac OS X

The Compose key is my method of choice for international character input. It lets me type characters as diverse as é Â ẃ ṗ § … « ¿ ¥ ¹ ½ © × using simple and intuitive key combinations.

How intuitive exactly? Let’s see:

  • Compose + C + , gives me Ç.
  • Compose + l + / gives me ł.
  • Compose + < + < gives me «.
  • Compose + - + > gives me →.
  • Compose + < + 3 gives me ♥.
  • Compose + C + C + C + P gives me ☭ (no kidding).

You can of course set up your own rules. This shit is so powerful that I cannot imagine I could ever use any other input method.

So, one would think that with all its glorious Unix heritage, Mac OS X would let you get the most out of your keyboard like the good old X11 system does. Well it turns out it’s possible, but not straightforward.

Fortunately, other people already did all the work. I will just indicate how to put their stuff together.

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. Fortunately, modern keyboards come with more and more idiotic and useless keys.

I use the Right Alt key as my Compose key. I already have a Left Alt 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 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:

The new option should appear. Activate it:

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. 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.

Step 4: restart all applications

And that’s it! Your Mac OS X system is now slightly more usable.

  • Posted: 2012-06-18 08:18 (Updated: 2015-09-05 19:38)
  • Author: sam
  • Categories: a11y osx tip

Attachments (4)

Download all attachments as: .zip

Comments

1. anonymous -- 2012-06-18 17:03

So you finally switched to Mac

2. anonymous -- 2012-06-29 15:29

For some reason I can't use the circumflex sequences (like compose ^ A → Â) with your DefaultKeyBinding.dict. Everything else seems to work nicely. Have you got any idea what might cause this or do you struggle with that problem as well?

3. sam -- 2012-06-29 15:41

@anonymous what comes to mind is the possibility that ^ is a dead key, meaning it behaves differently, though how exactly is yet to be determined. This is the case if you use for instance the US-International keyboard layout instead of the plain US layout: ^ ~ and ` become dead keys.

I should check when back home whether I have the same problem, but I have never been bothered because I use the > A → Â combination instead.

4. anonymous -- 2012-07-02 14:57

Thanks, compose > A → Â works fine. Maybe I'll adjust DefaultKeybinding.dict to remap all circumflex bindings (it's mostly superscript numbers) to greater-than.

5. sam -- 2012-07-03 10:10

@anonymous I really suggest trying to get rid of the dead key feature (probably by switching from US-International to US-English); if you use a Compose key the dead keys become a lot less relevant and you could probably do without them.

6. anonymous -- 2012-07-06 20:03

The problem persists throughout all US layouts I've tried. I guess there is some setting activated somewhere else I don't know about.

7. mach -- 2012-08-28 11:14

I have written an implementation of the compose key that does not use the Cocoa text system, but a keyboard layout: http://uscustom.sourceforge.net/. This comes down to the compose key being a deadkey. By using a keyboard layout instead of the Cocoa text system, the compose key will work in any application.

I have taken the liberty of giving the compose the same assignment you have chosen: Ctrl+Shift+F13. Like that, your KeyRemap4MacBook will work as well. I hope that is OK.

8. sirdharma -- 2012-10-22 00:49

@sam I understand you that you "cannot imagine you could ever use any other input method" (as stated in your article), but out of curiosity have you ever tried the way OS X allows you to enter international characters (by default)?

Using the U.S. keyboard layout (not even U.S. International which activates dead keys), one can enter all the accents in a way that I find very natural. The whole idea is that the accents are obtained through the letter you would use that accent with most of the time. This makes it very fast to use, and very easy to remember:

Alt+e → ´
Alt+u → ¨
Alt+i → ˆ
Alt+n → ˜
Alt+``
Alt+c → ç (you would not need the cedilla in an other letter anyway)

If you want to see how the different modifiers affect the keyboard layout, one can get a visual representation by selecting "Keyboard & Character Viewer" in Preferences System → Language & Text → Input Sources, and then selecting "Show Keyboard Viewer" in the Input Menu in the menu bar.

I find very surprising that very few people seem to measure how powerful the Cocoa text system is. Give a try to Ctrl+a, Ctrl+e or Ctrl+t (inherited from Emacs I believe), or the subtle difference between Command+Left/Right (move to beginning/end of line) and Alt+Up/Down (move to beginning/end of paragraph). And I could not live without Alt+Left/Right (move one word left/right) and Alt+delete backward/forward (delete one word backward/forward). There are tons of example which actually makes my typing experience in OS X better than in Linux (one of the main reasons being that they are consistent across all Cocoa applications, i.e. 95% of the applications I use).

I may add that I am French and that my first name is François, so accented characters are of primary importance to me ;)

9. jsarenik@email.cz -- 2013-12-18 10:18

Just for simplicity, I made a ready-to-use setup for KeyRemap4MacBook. Enjoy!

10. anonymous -- 2013-12-18 10:23

BTW: --KeyToKey-- should be __KeyToKey__

11. Risenup -- 2014-07-02 18:56

Hello...

12. david@cantrell.org.uk -- 2014-08-22 19:23

I've got a real Sun keyboard attached to my Mac, with a real Compose key that I'd like to use instead of Right Option. I know that it send key code 0x6e when I hit it, but do you have any idea what I should call it in the XML snippet instead of "Right Option"?

13. david@cantrell.org.uk -- 2014-08-22 19:37

Ah, figured it out myself, it's KeyCode::PC_APPLICATION

14. asedeno -- 2015-02-04 20:03

The problem with ^ (and ~, @, #, $) is that they are modifiers in DefaultKeyBinding.dict for Control (and Option, Command, Keypad, Shift). Even though they are written by Bob's tool in \UNNNN format, they still don't work right. Escaping them fixes it.

\U005E → \\\U005E (^)
\U007E → \\\U007E (~)
\U0040 → \\\U0040 (@)
\U0023 → \\\U0023 (#)
\U0034 → \\\U0024 ($)

Note that this escaping should only be applied to the keybindings, not to the insertText: directives.

15. dominique.quatravaux@epfl.ch -- 2015-03-25 16:53

Careful, your DefaultKeyBinding.dict starts with ~^$\UF710 which actually should be ^$\UF710 to mean Ctrl-Shift-F13. Please either revert, or update the recommended ~/Library/Application Support/Karabiner/private.xml to match (that's Karabiner instead of KeyRemap4MacBook) these days BTW)

16. sam -- 2015-09-05 19:37

@dominique thanks! I fixed the .dict.

17. anonymous -- 2015-09-06 14:41

KeyRemap4MacBook has been renamed to Karabiner...

253. anonymous -- 2016-10-28 20:24

Wow, spammers suck. Every comment since 18 is useless crap. :-(

254. suba hentai -- 2016-11-26 22:14

xyC2Fl I truly appreciate this post.Really thank you! Fantastic.

301. Full Article -- 2017-01-31 22:44

wvmisA I'а†ll right away take hold of your rss feed as I can not to find your email subscription hyperlink or newsletter service. Do you have any? Please let me recognise so that I could subscribe. Thanks.

303. More Help -- 2017-02-01 14:01

GwYw1E Im thankful for the article.Really thank you! Much obliged.

305. anonymous -- 2017-11-07 13:39

When the write key is applied with a key-board structure, it will continue to operate all over the OS in any program, not just in Cocoa programs as some shown at Dissertation Writing Service UK . It can be turned on and off with the UI by choosing another key-board structure and there is a visible reviews while writing the write combination

306. anonymous -- 2017-11-28 15:57

Play the most popular free online hearts card game one of the best sites for the players so have the full enjoyment to connect this link https://heartsgameonline.net online create the best score to play this hard thanks for the visit here.

307. anonymous -- 2017-11-28 16:03

You play the amazing free cell online card game and i sure you create the full enjoy the most popular site for the players just click this link https://abc2xyz.co/lllll so have the full fun i sure you create the best score to play the hard thanks for the visit here.

308. WalcottZelda -- 2018-01-23 10:42

It may be turned on and off with the UI by means of selecting any other key-board shape and there is a visible evaluation while writing the write aggregate. You've got a real sun keyboard attached to my Mac, with an actual Compose key that I might like to apply as opposed to proper choice. This comes all the way down to the compose key being a lifeless key. by using a keyboard layout instead of the Cocoa textual content gadget, the compose key will work in any software. Dissertation Help Service London

309. anonymous -- 2018-02-28 12:56

Such a helpful guide, going from a PC to a Mac initially is very challenging. Our Eastwood driveway contractors company recently made the change and had been struggling to getting the compose key setup properly, so thanks for this guide!

310. anonymous -- 2018-03-03 18:18

hi there

311. HBS Case Study Solution -- 2018-03-10 13:41

Science Channel’s Are Giving A Complete Knowledge To Its Viewers About Every Thing Students Write Done Dissertation On This Subjects And Show Its Importance http://casegurus.com/

312. anonymous -- 2018-03-11 20:43

Whenever I log into your blog I do find very interesting topics and informative articles published in it. This is the reason why I like visiting your blog very often. I even shared your blog link in my rushmyessay writers blog article where my friends also can come to know about your blog and have a look at it.

313. anonymous -- 2018-03-20 09:03

Very good post here. There are very useful information shared in this post. I am very happy to see this post and looking to see more good post.To get Garage Racking Click here http://rackinguk.uk/racking/garage-racking.html

314. shawnjasper -- 2018-04-09 14:11

I want to change one of my keys on my keyboard to a Compose key so I can easily type common accents or characters <a href="https://www.theacademicpapers.co.uk/assignment-writing-services-uk.php">Assignment writing services</a>

315. anonymous -- 2018-05-08 13:13

My friend recommended this blog and he was totally right keep up the good work https://www.engineeringassignment.xyz/civil-engineering-assignment-help-19703 Such a nice post, keep up the fantastic work Civil Engineering Assignment Help Service

316. anonymous -- 2018-05-08 13:14

This site and the resources you provide is really nice keep it up. https://www.examonlinehelp.xyz/take-online-english-exam-21168 Such a nice post, keep providing good resources. Take My Online English Exam

317. anonymous -- 2018-05-08 14:44

Such a nice post, keep up the fantastic work http://phphelponline.com/php-from-js-assignment-help-12777 This site and the resources you provide is really nice keep it up. Php From JS Assignment Help

Add New Comment