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 mapped my AltGr key to Ctrl with the following command:

setxkbmap -option ctrl:ralt_rctrl

However, when displaying the bindings with

xmodmap -pke

I can see that the keycode is associated to

   keycode 108 = Control_R Control_R Control_R Control_R

I would like to bind AltGr to LEFT Control. Is it possible?

This is important for Emacs, otherwise I don't get the same input when pressing C-S-b with the original Left Control or with AltGr.

share|improve this question
    
For those who might not know: 'AltGr' is the right hand 'Alt' key so labelled e.g. on a German keyboard. –  Anthon Jun 20 '13 at 7:10

1 Answer 1

up vote 0 down vote accepted

It maps to Control_R as that's how it's configured in XKB symbols for CTRL. Changing the configuration should result in Alt_R being mapped to Control_L. Note that with this method, your custom configuration will be overwritten by any future upgrades of xkeyboard-config (at least that's the package that owns /usr/share/X11/xkb/symbols/ctrl in Archlinux).
Open /usr/share/X11/xkb/symbols/ctrl, scroll down to this section:

// right alt functions as another ctrl key
partial modifier_keys 
xkb_symbols "ralt_rctrl" {
    replace key <RALT> { type[Group1]    = "TWO_LEVEL",
                         symbols[Group1] = [ Control_R, Control_R ] };
    modifier_map Control { <RALT> }; 
};

and replace Control_R with Control_L so that it reads:

// right alt functions as another ctrl key
partial modifier_keys 
xkb_symbols "ralt_rctrl" {
    replace key <RALT> { type[Group1]    = "TWO_LEVEL",
                         symbols[Group1] = [ Control_L, Control_L ] };
    modifier_map Control { <RALT> }; 
};

save & restart X then run:

setxkbmap -option ctrl:ralt_rctrl

check with xmodmap:

xmodmap -pke | grep 108
keycode 108 = Control_L Control_L Control_L Control_L

To make it permanent add setxkbmap -option ctrl:ralt_rctrl to your session start-up.
Alternatively, add ctrl:ralt_rctrl to your xorg.conf.d config files, e.g.:

Section "InputClass"
    Identifier         "Keyboard Defaults"
    MatchIsKeyboard    "yes"
    Driver             "evdev"
    Option             "XkbLayout" "us"
    Option             "XkbRules"  "evdev"
    Option             "XkbOptions" "ctrl:ralt_rctrl"
EndSection

Note to Gnome users: Gnome overrides xorg XKB options so one has to add ctrl:ralt_rctrl via gsettings (or dconf-editor):

gsettings set org.gnome.desktop.input-sources xkb-options "['ctrl:ralt_rctrl']"
share|improve this answer
    
I still get Control_R after a reboot: xmodmap -pke |grep 108 keycode 108 = Control_R Control_R Control_R Control_R Also a "No such schema 'org.gnome.desktop.input-sources'" error with gsettings. Any idea? –  z1naOK9nu8iY5A Jun 25 '13 at 15:45
    
I'm using Ubuntu 12.04 with Gnome and a french layout. –  z1naOK9nu8iY5A Jun 25 '13 at 17:26
    
@z1naOK9nu8iY5A - Apparently that gsettings key was added by the gnome devs after Ubuntu 12.04 release. That explains the error message you got there. Still, why your AltGr would still map to Control_R instead of Control_L is beyond me. You could as well try directly with xmodmap (assuming you reverted your xkb settings to default). That also works on my system but not for all apps. In one line: xmodmap -e "remove mod1 = Alt_R"; xmodmap -e "clear control"; xmodmap -e "keycode 108 = Control_L Control_L"; xmodmap -e "add control = Control_L Control_R" –  don_crissti Jun 25 '13 at 19:59

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.