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']"
The problem is that when you use a common modifier like AltGr, programs actually see it as being pressed when you use the AltGr arrows. So Shift + AltGr + i actually appears to a program as if you are pressing Shift + Alt + Up
and it's the addition of the extra Alt
that confuses the program. You can avoid this by either adding more shortcuts to the program if possible, so Shift + Alt + Up
does the same action as Shift + Up
, or you can use an uncommon modifier that the program is not aware of.
There are other ways of doing this, but this was one of the simpler ways and works well for me. It creates a "Group2" overlay on the alphanumeric keys, such that when you switch to Group2 you will have arrows there instead of letters. You can switch to Group2 with a toggle (on/off like Caps Lock normally works) or a momentary (press to activate, like Shift normally works)
partial alphanumeric_keys
xkb_symbols "alpha_arrows" {
key <AD07> {
symbols[Group2]= [ Home ] # u
};
key <AD08> {
symbols[Group2]= [ Up ] # i
};
key <AD09> {
symbols[Group2]= [ End ] # o
};
key <AD10> {
symbols[Group2]= [ Prior ] # p
};
key <AC07> {
symbols[Group2]= [ Left ] # j
};
key <AC08> {
symbols[Group2]= [ Down ] # k
};
key <AC09> {
symbols[Group2]= [ Right ] # l
};
key <AC10> {
symbols[Group2]= [ Next ] # ;
};
key <AB06> {
symbols[Group2]= [ Delete ] # n
};
};
You can then pick a key to use as a Group2 activation key. You can see all the options (if you don't want to roll your own) with this:
$ grep grp /usr/share/X11/xkb/rules/base.lst
Then pick an option, for example this one activates the arrows only while Caps Lock is being held. It also adds a new combination Alt + Caps Lock to actually switch caps lock on and off:
$ setxkbmap -option grp:caps_switch
You can add this into your Xorg config file to make the change permanent - there are plenty of guides online about how to do this.
Note that:
key
is used, as opposed to replace key
because we want to add to the existing definition, not replace it.
- If you actually have an alternate keyboard layout (possibly some international keyboards that can also type Latin/English letters), this method may not work for you. You will have to define a new type based on
ALPHANUMERIC
with extended modifiers (e.g. Hyper) to activate the arrow keys.
Best Answer
You can accoplish that with custom XKB map. I recommend you to dump the current map with
xkbcomp $DISPLAY dump.xkb
, edit it and load it withxkbcomp newmap.xkb $DISPLAY
. Dump file is pretty large and has a lot of superfluous information.Easiest way to go about the editing is to look up how the altgr is used in your current map. It's usually ISO_LEVEL3 modifier. If your current keymap does not use altgr, you can try loading one that does to see how it can be done. For example
-layout us -variant altgr-intl
is pretty extensive and has most if not all european keys bound. Below is a short primer of what's going on.xkb gets keycodes from kernel, sets a label for each and uses that label and modifier keys to decide what keysym it should output. Each key has a type assigned to it which defines what modifier keys it expects and what to output for each combination. Looking at the dump you got with
xkbcomp
: labels are defined inxkb_keycodes
, types inxkb_types
and label-to-keysym inxkb_symbols
. Of these,xkb_symbols
is the one you want to edit and reference the other two to know what to change. You can also just look at thexkb_symbols
and find how it's currently done and edit as appropriate.xkb_types
section holds different modifier levels for key definitions and you'll want to one which has altgr and shift modes. Example:That means that key marked as
FOUR_LEVEL_ALPHABETIC
has four modes. Normal, shift/caps, altgr, altgr-shift which sounds like what you're looking for.Now you want to find out what the keycode for w is if you don't know it already.
xev | grep -A2 --line-buffered '^KeyRelease' | sed -n '/keycode /s/^.*keycode \([0-9]*\).* (.*, \(.*\)).*$/\1 \2/p'
gives you the keycode for keys you press.grep
is there to make the output more readable.Cross-reference the keycode you got with
xkb_keycodes
section of the dump map you got earlier. For me, w gives keycode 25.less
the dump and find the correct keycode in form of<LABEL> = ##;
, example<AD02> = 25;
. Orcat dump.xkb| grep ' = 25;'
Label is just a name xkb uses to reference the key in later sections.Now that you have the label, go to
xkb_symbols
which actually maps the labels to keysyms. The format istype=
is the type you want fromxkb_types
section,symbols[Group1]=
has one keysym for each of the modes required by the type. Again, normal, shift/caps, altgr, shift-altgr for this type.[Group1]
, as far as I've understood is a method of using multiple keymaps you can change on the fly with a lock key you set up. I don't use groups myself so everything is group1 for me.to find all the different keysyms you can use here, check
/usr/include/X11/keysymdef.h
. The two symbols you're looking for areae
for æ andAE
for Æ.I may have rambled a bit. Check out Arch Wiki's page on XKB, it's good stuff no matter what OS or distro you're using.