Gnome: Map AltGr key to Alt

9,215

Solution 1

xmodmap

The 'shift, lock, control, modN' on the left are what X sees and cares about. The keysyms on the right map to them. Mode_switch is your AltGr key. Move it to join the others at mod1:

xmodmap -e 'clear mod5'
xmodmap -e 'add mod1 = Mode_switch'

Solution 2

gnome-tweak-tool lets you do this with a GUI:

Typing -> Key to choose 3rd level -> Right Alt key never chooses 3rd level

Solution 3

For those UK users still pulling their hairs out, this worked for me:

xmodmap -e "clear mod5"
xmodmap -e "keycode 108 = Alt_L"

Explanation: The first line removes the current behaviour of your AltGr (which is assigned to the mod5 modifier). The second takes the AltGr key (which on my keyboard produces a keycode of 108), and maps that to whatever keycode your Alt_L key is mapped to.

If you have no idea what is going on with keycodes and keysyms, I found this xmodmap introduction very useful.

Share:
9,215

Related videos on Youtube

ChrisInCambo
Author by

ChrisInCambo

Web developer based in Phnom Penh, Cambodia

Updated on September 17, 2022

Comments

  • ChrisInCambo
    ChrisInCambo almost 2 years

    I have an annoying UK keyboard which has an Alt Gr key where the right Alt key is on a US keyboard. This is really annoying when using Gnome which makes heavy use of the Alt/Meta key.

    Does anyone know how I can map the Alt Gr key to the Alt key?

  • ChrisInCambo
    ChrisInCambo over 14 years
    No that didn't work for me, fired up emacs and AltGr-v gives me “ instead of scrolling the page up as it would with alt-v.
  • Walter Kiess
    Walter Kiess over 14 years
    Those specific commands didn't work, or looking at the output of 'xmodmap' and moving the keysym didn't work? You can use 'xev' to help with this: run it, mouse over the window, and press modded keys.
  • ChrisInCambo
    ChrisInCambo over 14 years
    The command worked and here is the output of the xmodmap: 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 (0xce), Hyper_L (0xcf) mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb)
  • ChrisInCambo
    ChrisInCambo over 14 years
    Sorry for the mess, is seems like this site strips line breaks from comments.
  • Walter Kiess
    Walter Kiess over 14 years
    That output shows that you haven't cleared mod5, and that you haven't added Mode_switch to mod1. xmodmap -e changes like this are temporal: you can blow them away with setxkbmap, for instance.
  • ChrisInCambo
    ChrisInCambo over 14 years
    Sorry there was a reboot between when I entered the commands and recorded the output of xmodmap, maybe the changes aren't persistent? Anyway I've entered the command again and now xmodmap look like this: 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), Mode_switch (0xcb) mod2 Num_Lock (0x4d) mod3 mod4 Super_L (0xce), Hyper_L (0xcf) mod5 So the changes are showing, but if I still can't do CTRL-ALT-DEL in Gnome or use meta commands in emacs using AltGr.
  • Walter Kiess
    Walter Kiess over 14 years
    And if you also xmodmap -e 'add mod1 = ISO_Level3_Shift' ?
  • ChrisInCambo
    ChrisInCambo over 14 years
    Yes thanks alot, that nailed it! Are those changes persistent or will I loose them when I reboot?
  • Walter Kiess
    Walter Kiess over 14 years
    They are not persistent. I've put them in ~/.xsession for xdm setups, but linuxtopia.org/online_books/linux_beginner_books/… suggests that you put them in ~/.gnomerc
  • ChrisInCambo
    ChrisInCambo over 14 years
    Ok I've now noticed a problem, gnome is behaving like the alt key is constantly pressed, when I hit v for example in nautilus it opens up the View menu.
  • Walter Kiess
    Walter Kiess over 14 years
    If you're sure that this is related, you might: try removing the mode_switch keysym; change the keycode to generate Alt or Meta keysyms instead of dealing with the modifier table at all (xmodmap usage is similar: xmodmap -e 'keycode 123 = 4 5' -- look through xmodmap -pke)
  • ChrisInCambo
    ChrisInCambo over 14 years
    Ok cracked it with xmodmap -e 'keycode 203 = NoSymbol Meta_L NoSymbol Meta_L NoSymbol Meta_L'. If anyone else is trying this your key might not be 203, look for the key which calls Mode_switch and change it to the above.
  • Vomit IT - Chunky Mess Style
    Vomit IT - Chunky Mess Style about 7 years
    Link only answer say what??
  • rubo77
    rubo77 over 5 years
    In German: "Verhalten der Alt/Windows-Tasten" -> "Alt und Meta befinden sich auf den Alt-Tasten"
  • ACV
    ACV over 3 years
    This is working in Ubuntu 20.04 in year 2020 :)
  • Naidim
    Naidim over 3 years
    ^ This is the best solution.
  • ACV
    ACV over 3 years
    In Ubuntu 20.04 It is Tweaks -> Keyboard & Mouse -> Additional Layout Options
  • Kyle Baker
    Kyle Baker over 3 years
    For non UK users: This worked on my german keyboard as well, while the gnome-tweaks setting did not fwiw. Ubuntu 20.10 variant (pop os).