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']"
Best Answer
The keycodes file you've changed is an XKB mapping that defines the symbol codes used in XKB layouts (
<FOO>
) by the keycodes emitted by the kernel keyboard driver when a key is pressed. Changing the codes there doesn't change what code the key generates, it changes what code the XKB layout thinks its dealing with when it sees the altered symbol.Assuming you can get your system XKB files back to their original state, the XKB way to do what you want is to load an option that will override the standard layout. There's an existing option (
ctrl:ralt_rctrl
) that's close to what you want:You can load that with
setxkbmap
:If that does what you want, you can make it permanent by adding that command to a
.xprofile
or.xinitrc
or your window manager'sautorun
script. In GNOME you may need other steps.If you still prefer to have Alt_R remapped as Ctrl_L instead of Ctrl_R, you'd want to create a local override clause. Use the existing option as a starting point; it's in
/usr/share/X11/xkb/symbols/ctrl
. See my superuser answer on XKB modifications and some additional resources: