Wednesday, February 7, 2007

Accented characters with a US keyboard in X11

I've always been too busy to figure out how to map the useless Windows flag keys on my keyboard to do something useful in Linux/X11.

On traditional Unix systems, there's a Compose key. According to Wikipedia, "On some computer systems, a compose key is a key which is designated to signal the software to interpret the next keystrokes as a combination in order to produce a character not found on the keyboard."

To see what the Windows flag and menu keys are mapped to, I ran the following.

xmodmap -pk | grep 11{5,6,7}

This resulted in the following output:

115 0xff20 (Super_L)
116 0xff20 (Super_R)
117 0xffcc (Menu)

This output told me that the flag keys (left and right) were free to map to Multi_key. I figured I would leave the menu alone.

Next, I had to perform the remapping. I created a file, .Xmodmap, which is sometimes already there in a user's home directory. For me, it wasn't, so I went ahead and created .Xmodmap with these contents:

keycode 115=Multi_key
keycode 116=Multi_key

I then refreshed my keyboard mapping by running:

xmodmap .Xmodmap

To see if the re-mapping worked, I held the flag key down while pressing the n key, and typed in a tilde (~). The resulting character was the ñ character. Presto!