22

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

Braiam
  • 35,991
cedbeu
  • 622
  • Hm, I'm not following 100%, what would you like the Alt-Gr to do when you hit it? – Emanuel Berg Aug 01 '12 at 10:43
  • I would like it to be the Compose Key. Actually, I just would like to define a Compose Key somewhere, and since I'm used to have it on my Alt-Gr, I'd like to define it there. It's very easy to set up with a GUI, but I should be able to define it in pure console mode since I have no X system installed (it's not an option). I just can't figure out how. – cedbeu Aug 01 '12 at 11:03

2 Answers2

15

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.
Mikel
  • 57,299
  • 15
  • 134
  • 153
  • I'm not getting this to work. The dpkg-reconfigure wizard indeed asks about a compose key, but it says it does not work in "Unicode mode" (?). Also, when not in that mode, it says Control + period works as a compose key. But I'm not getting that to work either. – Emanuel Berg Aug 01 '12 at 17:14
  • I think that warning message refers to unicode_start. For me, it still works, provided I run setupcon as dpkg-reconfigure says. – Mikel Aug 01 '12 at 17:41
  • When I run setupcon in my X terminal (urxvt), it says "We are not on the console, the console is left unconfigured." Also, showkey complains "Couldn't get a file descriptor to the console". In tty, both those works but showkey says (the first thing) that "kb mode was UNICODE", so perhaps that is indeed why it is not working. But, the Control + period works in tty. OK, it makes sense now. – Emanuel Berg Aug 01 '12 at 17:59
  • Your question said you don't have X? You need to run setupcon on the Linux virtual console, e.g. Ctrl+Alt+F1. – Mikel Aug 01 '12 at 18:06
  • Right, like I said, it makes sense now. It wasn't my question, I just liked to try it out anyway. – Emanuel Berg Aug 01 '12 at 18:19
  • Ok, sorry to spam this thread with my mistakes but I must say that I was wrong, it does work exactly as described, I didn't do setupcon as superuser. That whole Unicode stuff is apparently something else. – Emanuel Berg Aug 01 '12 at 19:22
  • @cblab If my answer worked, please consider accepting it by clicking the check/tick mark. – Mikel Aug 02 '12 at 16:49
  • Sorry for the delay for accepting your answer, I didn't forget you :o] I found that dpkg-reconfigure way by myself in the while, and it's working great, though, I'm still struggling on how to redefine the compose keymap (weird, but on debian sid, it doesn't seem to be a standard compose keymap, I mean, with mod+o+c, I don't get the ©, or with mod+.+c, don't get ċ ...). But well, your answer definitely was well, and thank you then. Ah, just one thing, on my setup, the PrtScr key isn't defined as a Compose key, neither other ways you mentioned, but Ctrl+., + combination instead – cedbeu Aug 06 '12 at 17:46
  • 1
    Looks like console-setup doesn't support very many compose sequences by default. You can run dumpkeys --compose-only to see which ones. You should be able to modify the console-setup init script to add additional compose rules where it runs loadkeys. – Mikel Aug 06 '12 at 18:48
  • Yep thanks, I have seen the compose sequence allowed by default and indeed it's not a complete set as I wished, but I still have to investigate on how to define mine with loadkeys indeed. Thanks! – cedbeu Aug 07 '12 at 10:06
  • If this doesn't stick after a reboot, your system may be using IBus by default. Try running dconf write /desktop/ibus/general/use-system-keyboard-layout true – Mikel Jan 07 '20 at 21:11
3

"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 (~).