Override a few keycodes with XKB
Solution 1
Create a file containing your keycode changes, and save it as (for example) ~/.xkb/keycodes/local
. (The keycodes
directory is hard-coded; the base directory can be something else, and the filename too.) This will contain in your case
xkb_keycodes {
<PGUP> = 110;
<PGDN> = 112;
<DELE> = 115;
<INS> = 117;
<HOME> = 118;
<END> = 119;
};
To load this, run
setxkbmap -print | sed -e '/xkb_keycodes/s/"[[:space:]]/+local&/' | xkbcomp -I${HOME}/.xkb - $DISPLAY
This outputs your current settings, adds +local
to the xkb_keycodes
include
statement, and loads it into the XKB compiler, adding ~/.xkb
to the include path. (If you named your file something other than ~/.xkb/keycodes/local
, you'll obviously need to change +local
and -I${HOME}/.xkb}
.) That way all the other settings are preserved.
Solution 2
You can start by setxkbmap -print > somefile.xkb
to get the keymap you are using as a base, and then redefine the key names you want in the xkb_keycodes
section like this :
xkb_keymap {
xkb_keycodes {
include "evdev+aliases(azerty)"
// Custom <key name> = keycode
<INS> = 117;
<HOME> = 118;
<PGUP> = 110;
<DELE> = 115;
<END> = 119;
<PGDN> = 112;
};
xkb_types { include "complete"};
xkb_compatibility { include "complete"};
xkb_symbols { include "pc+fr+inet(evdev)"};
xkb_geometry { include "pc(pc104)"};
};
This generates warnings that some key names are assigned multiple times, but it works because only the last one count (so it's important to put the custom settings after the include). And the file have the advantage of being readable.
Another way is to dump the keymap you use into a file : xkbcomp $DISPLAY somefile.xkb
and modify the same lines (it is the same keymap with the includes evaluated). This way there is no warnings for multiple definitions, but it is less readable.
Related videos on Youtube
Gilles 'SO- stop being evil'
Updated on September 18, 2022Comments
-
Gilles 'SO- stop being evil' over 1 year
I want to shuffle a few keys around with XKB. (Why? On a laptop where some keys are inconveniently located.) I currently use xmodmap:
keycode 110 = Prior keycode 115 = Delete keycode 112 = Next keycode 117 = Insert keycode 119 = End keycode 118 = Home
Instead I want to use XKB and assign different symbolic names for certain physical keys, rather than assign different keysyms to certain keycodes. (This is why.) I want keycode 110 to send
PGUP
instead ofHOME
, keycode 115 to sendDELE
instead ofEND
, etc. The rest of the configuration must not be affected (soPGUP
is to keep sending the keysymPrior
, etc., and all other keys remain as they are).How can I change the assignment of these specific keycodes? I'll load a file with
xkbcomp somefile.xkb $DISPLAY
, what do I need to put insomefile.xkb
? -
Gilles 'SO- stop being evil' about 9 yearsWhere are all these names (
evdev+aliases(azerty)
, etc.) coming from? I explicitly want to perform a relative change, not a full reconfiguration. Keys other than the 6 listed in the questions must not be affected, they must remain in the state they were in when I issued the command. -
Leiaz about 9 yearsThey come from the
setxkbmap -print
, they are files from/usr/share/X11/xkb/
. I think you have to give a whole keymap toxkbcomp
but I could be wrong ... -
L. Levrel about 8 yearsSo this is the expected path and way to pass it to the
-I
switch! Thanks, I was unable to figure this out from the manpage. -
zw963 almost 6 yearsworked like a charm! it worked if want update xkb_symbols, just replace xkb_keycodes with it, worked