Home -> Content

Tutorial: Typing accented characters in X-windows

Synopsis

I wanted to be able to type accented and "international" characters with my US keyboard in X-windows with minimal hassle. After much searching, I found a solution that uses simple, easy to remember key sequences and only involved remapping one of my keyboard keys to be a Multi_key. The steps to do this mapping are outlined in this tutorial.

What is the Multi_key input method?

The Multi_key input method works as follows: you first type the key which you have defined as Multi_key and then you type a character sequence to get your accented character.

Example:

To get an 'é' (letter 'e' with an acute accent), I type a sequence of three keys (Num Lock, E, and then apostrophe):

  +----------+   +---+   +---+
  | Num Lock |   | E |   | ' |   =>   é
  +----------+   +---+   +---+
This is much slower than having dedicated keys for certain characters, but is particularly useful if you only need to enter the occasional accented character.

Step 1: Find a key to map to Multi_key

You need to choose a key which will become Multi_key. (Obviously choose one that you don't use currently.) If you have a Multi_key defined then you can probably just jump to the end of this tutorial.)

To examine your existing X-windows keyboard setup run xev which will show you all the X-Window events. (xev is a standard program that comes with X-windows).

You should see a small rectangular window open up. Move the cursor into the window. You should see lots of X events information output in the terminal window that is running xev.

Example:

    ...

    MotionNotify event, serial 18, synthetic NO, window 0x400001,
    root 0x30, subw 0x0, time 902755496, (130,166), root:(190,446),
    state 0x0, is_hint 0, same_screen YES

    MotionNotify event, serial 18, synthetic NO, window 0x400001,
    root 0x30, subw 0x0, time 902755506, (134,172), root:(194,452),
    state 0x0, is_hint 0, same_screen YES

    ...

While the cursor is in the window type various keys to see KeyPress and KeyRelease events.

Find a key that you want to change to Multi_key. Type the key and stop xev. You may need to scroll back in the output, but you should find the numeric keycode for the key.

Example:

I'm changing my Num_lock key. From the output of xev I can see that the keycode is 77.


    ...

    KeyPress event, serial 18, synthetic NO, window 0x400001,
    root 0x30, subw 0x0, time 903047602, (115,37), root:(235,357),
    state 0x0, keycode 77 (keysym 0xff20, Num_lock), same_screen YES,
    XLookupString gives 0 characters:  ""

    KeyRelease event, serial 21, synthetic NO, window 0x400001,
    root 0x30, subw 0x0, time 903047692, (115,37), root:(235,357),
    state 0x10, keycode 77 (keysym 0xff20, Num_lock), same_screen YES,
    XLookupString gives 0 characters:  ""

    ...

Step 2: Change the key mapping

To change the meaning of the keycode, use the standard X-windows program xmodmap.

Example:

To convert my Num_lock key (keycode 77) to Multi_key, I ran the following command:


  xmodmap -e "keycode 77 = Multi_key"

If you run xev again, and type Num_lock key, you should see the same keycode, but a different function.

Example:


    ...

    KeyPress event, serial 18, synthetic NO, window 0x400001,
    root 0x30, subw 0x0, time 903048602, (115,37), root:(235,357),
    state 0x0, keycode 77 (keysym 0xff20, Multi_key), same_screen YES,
    XLookupString gives 0 characters:  ""

    KeyRelease event, serial 21, synthetic NO, window 0x400001,
    root 0x30, subw 0x0, time 903048692, (115,37), root:(235,357),
    state 0x10, keycode 77 (keysym 0xff20, Multi_key), same_screen YES,
    XLookupString gives 0 characters:  ""

    ...

Step 3: Test entering accented characters

There is a file for each character set which lists all the mappings for the Multi_key technique for entering accented characters. The file is:
    /usr/X11R6/lib/X11/locale/[character set]/Compose
Where [character set] is the character set you are using. (Your default character set is probably ISO 8859-1, also known as "Latin1", which includes US_ASCII and supports most western european languages).

Example:

For the Multi_key mappings for the ISO 8859-1 character set, view the file:

    /usr/X11R6/lib/X11/locale/iso8859-1/Compose

Step 4: Edit startup files

If your X-windows is setup properly you should have a file .Xmodmap in your home directory. You can add the Multi_key mapping to this file.

Example:


    keycode 77 = Multi_key 

My .Xmodmap file doesn't seem to get loaded when I start X-windows, so I added the following to my .xinitrc instead:

  xmodmap -e "keycode 77 = Multi_key"

That's it. You should now be able to enter accented and international characters.

If you have any questions, or find anything unclear, you can always contact me.

Have a suggestion about this page? Send a quick comment:


  Note: include your email address if you would like a reply.

iphone apps

Deutsch Meister App Icon

Deutsch Meister

Build up your German!

Self-Hypnosis App Icon

Self-Hypnosis

Helping you to visualize and realize your goals.

BigNames App Icon

BigNames

An extra-large, easy-to-read contact list.

Cosmos Timer App Icon

Cosmos Timer

Create short, medium and long-term timers.

GoSwedish App Icon

GoSwedish

A friendly introduction to Swedish.

Happiness Application Icon

Happiness

A Guided Meditation