How can Windows emulate the functionality of the ComposeKey of UNIX?

by Michael S. Kaplan, published on 2005/01/22 16:46 -05:00, original URI:

Lionel Fourquaux asks:

As a member of a student group that provides some help with MS products, I've been trying to create a keyboard layout that would give a (partial) answer to a common complaint from Unix users: how to get a "Compose" key in Windows.

First, I've to say they won't be completely satisfied, since it appears to be impossible to reproduce, at least with MSKLC, the exact behavior they want. (It probably possible to do it by filtering keyboard events at a higher level, but it doesn't look as clean a solution).

First, to explain a bit about the Compose key if you have never heard of it before....

Looking at a definition in a description of KEYMAPS:

Compose Definitions

Then there may also be compose definitions. They have syntax
compose ’char’ ’char’ to ’char’
and describe how two bytes are combined to form a third one (when a dead accent or compose key is used). This is used to get accented letters and the like on a standard keyboard.

At first glance they are a lot like dead keys, right?

Well, not exactly. After all, one does not a key to change the behavior of another key to make it act like a dead key. Thus a line in the KERNEL ACCENT TABLE that looked like "compose ’,’ ’c’ to ccedilla" would mean that typing <ComposeKey><,><c> would create <ccedilla>. And that just typing <,><c> without touching the Compose key would not. Of course, with dead keys in Windows keyboards (like those you can define in MSKLC) there is no exact conditional mechanism like that.

Now you could fake it, though. And it would not be such a bad fake.

You could define your dead keys in the AltGR state such that any time you typed <AltGR><,> followed by <c> you would get what you wanted. You could optionally define <AltGR> + <c> to put out that same lowercase 'c' if you wanted that same behavior when the faux-compose key was held down.

Of course this method is kind of expensive; you have to be willing sacrifice AltGR as a shift state (you are putting in otherwise unexpected definitions to support the Compose functionality anyway, and it would be incredibly confusing to have the AltGR perform other tasks as well. But if you turn your AltGR into a faux-Compose key consistently in the definition, then your keyboard layout would certainly act like it has a Compose key.

Note that other Unix-type functionality (loading the Compose key definitions into arbitrary keyboards) would not exist and could never really be added. You would have to look into the SetWindowsHookEx API with one of the keyboard hook types to try to affect keyboard behavior in such a marked way. This is of course a pretty extreme way of getting such a task done and it is worth really considering whether such a functionality is a sensible thing to have (given the differences in the overlap of letters that are needed across languages).

In any case, Lionel then continued:

Second, it appears that MSKLC really doesn't like want I'm trying to do: it doesn't signal any clear problem, but some keys in the resulting layout do not work as they should and as they do in the test window. I've tried many variations, and I suspect that I've hit either a bug or an undocumented limitation.

Recently someone in the newsgroups reported a specific bug in an experimental (one could almost call it an MSKLC stress test!) keyboard with 17 different dead keys and over 300 dead key pairs defined was having some problems in two of those dead key definitions (in the VK_OEM_5 and VK_OEM_7 definitions); I will be investigating that report soon. Is this a similar type of problem?

# Peter da Silva on 22 Jan 2005 4:42 PM:

The Compose key provides a lot more than just accents. For example, compose-1-2 gives you [1/2] and compose-3-4 gives you [3/4] and compose-dash-L gives you [pound] and compose-slash-c gives you [cent]. It's a two-key-mnemonic for all kinds of characters not on the standard keyboard, and is much easier to remember than the equivalent mechanisms in MacOS and Windows.

When we needed this functionality for our customers a few years ago we bought an application called "Kovach Accent Composer". It still seems to be available:

It was very well recieved by our customers, and while I haven't used it myself in some years it was a lifesaver and I can't recommend it enough.

Disclaimer: I have absolutely nothing to disclaim, I know absolutely nothing about KCS or Dr. Warren Kovach, and my only relationship with them is as a customer. I only wish they had a version for the Mac. :)

# Michael Kaplan on 22 Jan 2005 5:15 PM:

I never claimed it was only for accents -- I was talking about typing a dead key, which as I described at and just involve typing two characters to make a third.

All of your examples would be covered by that (only the Unix doc seemed to limit them to accents).

# Lionel Fourquaux on 23 Jan 2005 9:25 AM:

Peter: I'm aware that several applications on the web provide a Compose key emulation for Windows. However, they all use message hooks to post-process the input, which is far from being as clean as creating a new keyboard layout. (Moreover, I vaguely remember reading that hooks are not always as reliable as they should be).

Michael: I'm afraid I'm the same person who reported the problem with this (somewhat ridiculous) keyboard layout. I didn't realize at first that posting in the newsgroups would be a more appropriate place.

From what I've recently read in your blog, it'd be possible to "chain" dead keys (i.e. that dead key + another key is yet another dead key). I've not looked into this more precisely (and I'll probably not do it soon), but I think this is exactly what is needed to get a Compose key. Even if MSKLC doesn't expose this possibility, the internal keyboard layout mechanism appears to be powerful enough to solve this problem. (Maybe I'll give it a try someday).

This complaint about the Compose key seems rather frequent from people used to Unix OSes.

# Michael Kaplan on 23 Jan 2005 10:23 AM:

Well, so far every example that has been given still ends up as COMPOSE plus two keystrokes to get a specific character.

Chaining dead keys would involve three keystrokes plus COMPOSE to get a specific chsracter. Unless COMPOSE has more functionality than the orevious examples give it?

Or unless one is not expected to hold down the COMPOSE key when one holds down the other keys? The description is not clear....

# Paul on 23 Jan 2005 9:54 PM:

No, you don't hold down the compose key... you just press it. Compose, then ', then e, gives you é.

# Michael Kaplan on 23 Jan 2005 10:08 PM:

Ok, cool, that answers me.... and yes, there is no such key in Windows nor a way to get such a key with a standard keyboard.

But other than a little learning, it is hard for me to see it as looking particularly better or worse than the dead key mechanism (and in fact it is fewer key presses with dead keys!).

# Lionel Fourquaux on 25 Jan 2005 10:59 AM:

In fact, some people press the compose key first, the some sequence of keys, while others press the compose key and the first key of the sequence simultaneously.
I've no opinion as to whether it's a better idea than dead keys, or not. Both are clearly related. What I see is that there is a strong demand for this functionality among people used to Unix OSes.
As for whether you can define such a key with the standard Windows APIs, what about this: define you compose key as a dead keys, and use chained dead keys to build compose key sequences as a tree of chained dead keys: e.g. compose is a dead key, which gives another dead key if you press 1, and this second dead key gives you ½ if you press 2. If I understand correctly how dead keys can be chained, I think it gives you exactly a Unix-style compose key. Have I overlooked some problem?
Another difficulty is which physical key to use for compose. Many people use the "Application" key (the one with a small picture of a menu) for this purpose, but it'd cause conflicts with Windows keyboard shortcuts. A solution would be to use a key plus a modifier (e.g. AltGr+k).
A simpler solution is to use dead keys, and don't bother to mimic another OS when the benefits are not obvious!

# Michael Kaplan on 25 Jan 2005 11:51 AM:

But chained dead keys do not specifically help, as it would then require three keystrokes and there is no option for typing the letters without the combination happening.

In the end, I am forced to believe that the last idea is the way. :-(

Better to let Windows be Windows. It is not specifically better or worse in this case, just different....

# Gerben Vos on 16 Sep 2008 8:55 AM:

Dead keys *are* less practical. When I press comma, I want a comma; I don't want this key to have different results (comma or cedille) depending on what key I press next. A compose key gives an easy choice between the comma and the cedille. It's a simple matter of offering a consistent and easy-to-remember user interface.

The Unix (or at least Linux) compose key does use more than two keys for some combinations; for example, Compose - - . gives an en-dash, while Compose - - - gives an em-dash. They may not be perfect key combinations, but they *are* easy to remember (and let's face it, you don't have to use those dashes very often).

# Gerben Vos on 16 Sep 2008 9:52 AM:

I would like to point lovers of the compose key to , where there are several choices, all apparently MSKLC-generated. The layouts "Pseudo VT320, "United States International Alternate", "United States Combining Diacritical" all look quite promising.

# Lapo Luchini on 29 Oct 2009 4:30 AM:

IMHO AllChars is the solution to emulate compose key on Windows:

I don't know its internals, but it's opensource and it works; I used it for a few days and am very very satisfied so far.

Simon on 15 Aug 2013 2:24 AM:


>  ... you have to be willing sacrifice AltGR as a shift state...

I have never net anyone who used the AltGr key in the English speaking world using EN-GB keyboard.  The same for Alt on EN-US local keyboards - Who uses these, other than to access accents chars?

Thanks for this article. Perhaps there lies a method that I can use Alt for a deadkey to access French accented characters : One day...


Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

referenced by

2005/11/15 It is not easy to chain dead keys on Windows

go to newer or older post, or back to index or month or day