How to define a Compose Key in terminal (no desktop environment)?

I would like to define a compose key on my system (Debian Sid “Wheezy”). I have no Xorg (and don’t want any desktop environment). Only in terminal.

I would like to set it up on my Alt-Gr key (right Alt). I’ve tried for a while but I can’t figure out how to set it up.

I’ve been investigating and found some directions:

  • $ showkey gives me the keycode of my Alt-Gr key (#100)
  • $ dumpkeys and $ dumpkeys --compose-only output “the current contents of the keyboard’s driver”, in the format specified by keymaps, according to the man page
  • $ loadkeys load a keyboard translation table

I’m sure it’s not that difficult but I miss how to deal with that …

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

On newer Debian and Ubuntu systems, your keyboard settings are put in /etc/default/keyboard and shared between X and the console. Just run

sudo dpkg-reconfigure keyboard-configuration

and select Compose key: Right Alt (AltGr) on the appropriate screen.

You could also put XKBOPTIONS=compose:ralt in /etc/default/keyboard and run

sudo dpkg-reconfigure console-setup

Older systems have a Compose key on the console by default. In the us layout, pressing both Alt keys together acts like Compose.1

For example: Alt+AltGr, ", A => Ä

If you prefer AltGr only to be Compose, you need to change

alt keycode 100 = Compose

in your active keyboard map to
keycode 100 = Compose

The easiest way to do this is to make the above changes in /lib/kbd/keymaps/i386/include/linux-with-alt-and-altgr.inc.

A better way is to create a new file called /lib/kbd/keymaps/i386/include/altgr-is-compose.inc with the above line, create a new keymap that includes it, and set that to your default keymap.

  1. PrtScn also acts as Compose by default.

Method 2

“compose” on the console allows to type two characters but output a third one.

the problem is that the compose definitions use bytes, both as the two input (that is, you can’t define compose in terms of typed keys but only in term of typed symbols) and for the output.

to make it work in UTF-8, which is multibyte (1 to 4 bytes, at least) would require great changes in the way console input is handled, and replace the simple char array currently used by something more complex. It seems there aren’t plans to do so (the consensus among kernel devlopers is that console should remain a console, something simple, only used for last ressort; if you actually need unicode then you likely also need bidi, shaping, etc; then it is better to run a graphical terminal (an fullscreen xterm on X11; but there are other possibilities).

So, indeed it doesn’t work, and won’t work, with multibyte characters on console.
BUT, it still works if you restrict the compose definitions to plain ASCII.

And I also found out that it also works if the output is in iso-8859-1 (that correspond to unicode values up to 0x00ff); for that you can put in some start script a line:

    loadkeys /somepath/somefile

and put in that file the compose definitions you want (be careful to save the file in ISO-8859-1 encoding; and use chars bigger than 0x7f as the output only)
the syntax of such a file is very simple, lines like this:

    compose 'somechar' 'somotherchar' to 'desiredoutput'

eg:

    compose 'a' 'a' to 'å'
    compose 'a' 'e' to 'æ'

the apostrophe has to be escaped.

the effect of dead diacritics keys are also defined in that file; for dead_acute + a you define a line like:

    compose ''' 'a' to 'á'

dead_grave uses backtick (`), dead_diaeresis uses doublequote (“), dead_circumflex uses circumflex (^) and dead_tilde uses tilde (~).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments