12

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?

Jawa
  • 3,619
  • 13
  • 31
  • 36
ChrisInCambo
  • 253
  • 1
  • 2
  • 5

5 Answers5

11

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

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

Andrew Bruce
  • 111
  • 1
  • 2
8

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.

cammil
  • 252
  • 2
  • 8
  • 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). – Kyle Baker Mar 26 '21 at 09:55
1

====Change AltGr to Alt in Gnome

Click on Show Applications > Settings > Keyboard > In Special Character Entry click on Alternate Characters Key > Put Use layout default to Off > Click on None.

In Special Character Entry also click on Compose Key > Put Use layout default to Off > Click on Left Alt > Put Use layout default to On.

To test if it works correctly start the Terminal. Write a short text, for example “Write a short text.” Press Right Alt and B at the same time. If the the cursor goes back a word it works as it should.

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'
ayrnieu
  • 287
  • 1
  • 4
  • 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. – ChrisInCambo Oct 09 '09 at 04:28
  • 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. – ayrnieu Oct 09 '09 at 05:05
  • 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 Oct 09 '09 at 05:11
  • Sorry for the mess, is seems like this site strips line breaks from comments. – ChrisInCambo Oct 09 '09 at 05:11
  • 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. – ayrnieu Oct 09 '09 at 05:17
  • 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. – ChrisInCambo Oct 09 '09 at 05:34
  • And if you also xmodmap -e 'add mod1 = ISO_Level3_Shift' ? – ayrnieu Oct 09 '09 at 05:39
  • Yes thanks alot, that nailed it! Are those changes persistent or will I loose them when I reboot? – ChrisInCambo Oct 09 '09 at 06:08
  • They are not persistent. I've put them in ~/.xsession for xdm setups, but http://www.linuxtopia.org/online_books/linux_beginner_books/debian_linux_desktop_survival_guide/GDM_Startup.shtml suggests that you put them in ~/.gnomerc – ayrnieu Oct 09 '09 at 06:10
  • 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. – ChrisInCambo Oct 09 '09 at 13:42
  • 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`) – ayrnieu Oct 09 '09 at 14:37
  • 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. – ChrisInCambo Oct 09 '09 at 15:50
0

If the above answers still do not work you then run xev -event keyboard (you may need to install it first) and press AltGr with the Event Tester window in focus. You should see something like the following in the shell.

KeyPress event, serial 163, synthetic NO, window 0x1600001,
    root 0x119, subw 0x0, time 21667560, (151,737), root:(1111,764),
    state 0x10, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
    XKeysymToKeycode returns keycode: 92
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

On the third line it gives you the keycode and keysym name, which in my case is ISO_Level3_Shift. Now run xmodmap and check the output before doing

xmodmap -e "remove mod5 = ISO_Level3_Shift"
xmodmap -e "add mod1 = ISO_Level3_Shift"

where ISO_Level3_Shift should be replaced with the correct key symbol if necessary. Finally you need to add this to your user rc script to make it persistent.

DavidPostill
  • 153,128
  • 77
  • 353
  • 394