Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question
    
Hm, I'm not following 100%, what would you like the Alt-Gr to do when you hit it? –  Emanuel Berg Aug 1 '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 1 '12 at 11:03

2 Answers 2

up vote 6 down vote accepted

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.
share|improve this answer
    
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 1 '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 1 '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 1 '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 1 '12 at 18:06
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 6 '12 at 18:48

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

share|improve this answer
    
Thanks, got it to work. Only, I had to change compose 'a' 'a' to 'å' into compose 'o' 'a' to U+00E5, otherwise loadkeys complained about a syntax error. –  Emanuel Berg May 11 '13 at 0:32
    
when you used 'å', did you wrote the file in iso-8859-1 (not utf-8)? –  Pablo Saratxaga May 24 '13 at 19:59
    
I don't know. How do I check that? –  Emanuel Berg May 25 '13 at 23:37
    
to test if a file is in utf-8: iconv -f utf-8 -t utf-8 filename if no errors, it is in utf-8 –  Pablo Saratxaga May 28 '13 at 1:15
    
That seem to cat the file, but no, there are no errors on echo $? at least, and no output to stderr. Also, file tells me it is UTF-8 so it makes sense. –  Emanuel Berg May 29 '13 at 15:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.