Map AltGr-[a..z] and Shift-AltGr-[A..Z] to greek letter

6,016

Solution 1

This is a long answer. If you want a TL;DR version --- xmodmap is sort-of deprecated; layout switches will reset it; go to the section called "and finally, I did it" at the end for my solution.

I suppose you have your AltGr-something working already. It will depend on your keyboard configuration to have it activated or not. On my PCs, it works with Spanish and US-International but NOT on plain US keyboard.

The method I use is with xmodmap, but it works only partially: if it works or not will depend on your layout and even then it will be reset every time you change layout. See later for the "real" (but complex) solution.

You can use xmodmap by following these steps:

1) In a terminal issue

xmodmap -pke > mykeydefs.lst

(extension and name free --- use what you like)

2) edit the file; you will see a bunch of lines like...

keycode   8 =
keycode   9 = Escape NoSymbol Escape
keycode  10 = 1 exclam 1 exclam bar exclamdown
keycode  11 = 2 quotedbl 2 at at oneeighth
keycode  12 = 3 periodcentered 3 numbersign numbersign sterling

These are your keyboard definitions. Find for example the entry for A:

keycode  38 = a A a A ae AE

This means that pressing this key you have "a", shift+key "A", etc... the interesting ones are the 5th and 6th (1), which are normally associated to ALtGr and Shift+AltGR. Pressing AltGR + A you should have the symbol "æ".

If you have more than 6 entries, try to see which ones are activate by your AltGR combination: for example, if you have

keycode  38 = a A a A ae AE aring Aring

and you have an å when pressing AltGr-A, the entry to modify will be the 7th and 8th...

3) change the line to

keycode  38 = a A a A Greek_alpha Greek_ALPHA

(capitalization is important). You can edit all the lines you want; it is better if you delete all the lines you left untouched. The list of all the symbols is here, but take into account that if they are visible or not depend on the font you are using, too. Save the file.

4) Reload the new mapping

xmodmap mykeydefs.lst

This command must be silent --- if it shows any error, the map is not loaded.

5) test it. Now pressing AltGr + a should give the symbol alpha (well, alpha letter greek in Unicode, really).

6) if it works, you can set the command in the list of your startup commands.

The real solution (hints at it, at least)

If the xmodmap method does not work, you'll need to edit your keyboard layout. I have found some interesting links:

  1. An howto and a thread on creating your own keyboard layout.

  2. A quite complete guide to the XKB system.

  3. A blog entry on making local modifications to your layout.

And finally, I did it:

  1. A little example of a direct modification to the system files (I could not find how to do that in your local ~/.xkb directory).

  2. A nice configuration to have all the greek letters with a single modifier.


Footnotes:

(1) by the way, in all manuals and instructions around it is said the "mode_shift" chars should be the third and the fourth. Which on Ubuntu are not, and I can't really find any documentation with details. If anyone can point it to me, I will be grateful.

Solution 2

Enable Compose Key in dconf-editor to set up AltGr

Within dconf-editor go to org>gnome>desktop>input sources. Edit the entry xkb-options to set the Compose Key you wish, such as ['compose:ralt'].

This earlier answer includes terminal commands as well: Make "super/window" as compose key in Ubuntub

Using Compose Key will give you lots of additional characters quickly but Greek letters are not included without additional keystrokes.

For quick access to Greek letters use IBus to switch between your usual keyboard layout and the Greek alphabet. IBus may appear in your main menu as "Keyboard Input Methods". You can install it with sudo apt-get install ibus.

After you start IBus add the "Greek, Modern" layout under the "Input Method" tab. In the "General" tab you'll find the method to quickly switch keyboard layout. In my case it's Win+Space. By pressing that combination you immediately switch to Greek layout and pressing a gives α (alpha).

With this method you stay with Greek until you switch back to your home layout with Win+Space.

Share:
6,016

Related videos on Youtube

Alexandre Holden Daly
Author by

Alexandre Holden Daly

Updated on September 18, 2022

Comments

  • Alexandre Holden Daly
    Alexandre Holden Daly over 1 year

    I'm on Ubuntu trusty, and I use greek letters for algebra. I'd love to be able to type them in quickly with Alt Gr-letterKey.

    For example, map alpha to Alt Gr-A, map beta to Alt Gr-B, map theta to Alt Gr-T, etc.

    This page explains how to do it on an earlier version of Ubuntu. When I try following it, I can go to System Settings -> Keyboard -> Typing -> Compose Key.

    But when I get to Compose Key, it says that it's 'disabled'. Nothing happens when I click the row and hold down new keys, nor when I press backspace to clear. Even if it did work, I don't see how that would enable to me to re-assign Alt Gr-[A..Z].

    Can anyone help?

  • Alexandre Holden Daly
    Alexandre Holden Daly about 10 years
    thanks! very newbie-ish question, but how do I navigate to org? I can't find it in /, and find / -name org returns a lot of paths.
  • Sean
    Sean about 10 years
    @AlexandreHoldenDaly Sorry, "org>gnome>desktop>input sources" are within dconf-editor, they aren't directories on the computer.
  • Alexandre Holden Daly
    Alexandre Holden Daly about 10 years
    thanks again. when I get to xkb-options its value is set to []. When I click on [] it lets me edit it. substituting it for compose:ralt doesn't work, but ['compose:ralt'] does. What does this do though? How do I map eg AltGr-A to alpha?
  • Sean
    Sean about 10 years
    @AlexandreHoldenDaly Sorry was focused on "AltGr" instead of your ultimate goal. I've revised answer with this in mind.
  • Alexandre Holden Daly
    Alexandre Holden Daly about 10 years
    thanks for such a detailed reply! I tried that and sadly it didn't work - I think the mapping in mykeydefs.lst isn't the one that's used by the OS for interpreting keyboard input. eg in I now have keycode 38 = a A a A Greek_alpha Agrave Acircumflex but AltGr-A types in å. In system settings -> Keyboard -> Layout Settings, Input sources to use is set to English (UK, extended WinKeys). Do I need to modify the input source to something else?
  • Rmano
    Rmano about 10 years
    Hmmm... you have more than six entries for the key? This is quite strange. Do you have any output/error when you load the new map with xmodmap? I have checked with my spanish keyboard, but will double check at home with an US-international keyboard. What is the output of "xmodmap" (w/o options)?
  • Alexandre Holden Daly
    Alexandre Holden Daly about 10 years
    thanks a lot for the help. the output is xmodmap: up to 4 keys per modifier, (keycodes in parentheses): shift Shift_L (0x32), Shift_R (0x3e) lock Caps_Lock (0x42) control Control_L (0x25), Control_R (0x69) mod1 Alt_L (0x40), Meta_L (0xcd) mod2 Num_Lock (0x4d) mod3 mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce), Hyper_L (0xcf) mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb)
  • Alexandre Holden Daly
    Alexandre Holden Daly about 10 years
    (that doesn't look very clear.. if you want I can copy that output again with a |< sign to tell you when it's new line)
  • Rmano
    Rmano about 10 years
    ...it's the same than mine. I suppose you will need to define your own layout... the link is: ubuntuforums.org/showthread.php?t=188761 (seems that xmodmap works only by accident!)