Gnome: Map AltGr key to Alt

7

4

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

Posted 2009-10-09T03:49:35.763

Reputation: 203

Answers

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

Posted 2009-10-09T03:49:35.763

Reputation: 279

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 – 2009-10-09T04:28:17.933

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 – 2009-10-09T05:05:04.410

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 – 2009-10-09T05:11:08.127

Sorry for the mess, is seems like this site strips line breaks from comments. – ChrisInCambo – 2009-10-09T05:11:41.887

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 – 2009-10-09T05:17:48.300

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 – 2009-10-09T05:34:15.647

And if you also xmodmap -e 'add mod1 = ISO_Level3_Shift' ? – ayrnieu – 2009-10-09T05:39:20.880

Yes thanks alot, that nailed it! Are those changes persistent or will I loose them when I reboot? – ChrisInCambo – 2009-10-09T06:08:30.617

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 – 2009-10-09T06:10:35.463

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 – 2009-10-09T13:42:29.450

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 – 2009-10-09T14:37:55.763

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 – 2009-10-09T15:50:21.783

7

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

Posted 2009-10-09T03:49:35.763

Reputation: 234

4

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

Posted 2009-10-09T03:49:35.763

Reputation: 41

Link only answer say what?? – Pimp Juice IT – 2017-05-09T02:58:42.020

In German: "Verhalten der Alt/Windows-Tasten" -> "Alt und Meta befinden sich auf den Alt-Tasten" – rubo77 – 2018-10-13T11:44:24.483

1

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.

Richard Palethorpe

Posted 2009-10-09T03:49:35.763

Reputation: 11