1

If I remap keys for user with xmodmap

xmodmap -e "keycode 135 = Super_R"

settings disappear and stop working after some time or when I reconnect keyboard. So I'm looking for permanent solution.

Changing aliases as suggested and restarting xorg doesn't work at all

/usr/share/X11/xkb/keycodes/evdev
alias <MENU> = <COMP>;
to
alias <MENU> = <SUPR>;

Right Menu still works as menu and xev shows keycode 135 (keysym 0x0, NoSymbol).

setxkbmap -print -verbose 10

Applied rules from evdev:
rules:      evdev
model:      pc105
layout:     dvorak,ua
options:    grp:shifts_toggle,caps:escape,keypad:pointerkeys,caps:swapescape
Trying to build keymap using the following components:
keycodes:   evdev+aliases(qwerty)
types:      complete
compat:     complete
symbols:    pc+us(dvorak)+ua:2+inet(evdev)+group(shifts_toggle)+capslock(swapescape)+capslock(escape)+keypad(pointerkeys)
geometry:   pc(pc105)
xkb_keymap {
        xkb_keycodes  { include "evdev+aliases(qwerty)" };
        xkb_types     { include "complete"      };
        xkb_compat    { include "complete"      };
        xkb_symbols   { include "pc+us(dvorak)+ua:2+inet(evdev)+group(shifts_toggle)+capslock(swapescape)+capslock(escape)+keypad(pointerkeys)"    };
        xkb_geometry  { include "pc(pc105)"     };
};

Why aliases don't work? What is the other way to make remapping permanent even when keyboard is reconnected?

2
  • What's your desktop environment? It's a little different depending on if you use Gnome, KDE, XFCE, Cinnamon... Also, what is the location of the taskbar, top or bottom of the srceen? Commented Aug 21 at 19:03
  • JayCravens, I use only window manager. And would like to use universal method that will work on any DE. And I found it. It is possible to remap keys in udev on kernel level. Commented Aug 21 at 21:10

4 Answers 4

1

Try keyd! A key remapping daemon for linux.

From their repo:

Linux lacks a good key remapping solution. In order to achieve satisfactory results a medley of tools need to be employed (e.g xcape, xmodmap) with the end result often being tethered to a specified environment (X11). keyd attempts to solve this problem by providing a flexible system wide daemon which remaps keys using kernel level input primitives (evdev, uinput).

keyd github repo

# /etc/keyd/default.conf
[ids]
*

[main]
Menu = layer(meta)
1

Use xev to get the keycode for your menu key.

xev

Depends a bit on the distro what package this is from, usually something like xorg-xev

You will get something like

state 0x0, keycode 135 (keysym 0xff67, Menu)

With that knowledge you can do

xmodmap -e "keycode 135 = Super_L"

This should rebind the menu key to super.

If you mess something up, you should be able to reset your configuration with this command:

xmodmap ~/.Xmodmap

And to make it permanent, you add this line to ~/.Xmodmap:

keycode 135 = Super_L

Worst case, if the xmodmap -e command works but the rest doesn't, you can just configure your environment to autorun the command on startup.

I am largely going off memory and web searches here because it has been a while since I used X daily, I just remember xmodmap was the best way to do something like this, by far, I haven't actually found a satisfactory solution for remapping keys when not on X (e.g. on wayland), there are solutions, keyd as suggested by white-hat-er is one of them, but it leaves a lot to be desired if you don't have a standard US layout keyboard, and all the other options have some quirks and complexities to them as well, there's no method to do it as cleanly as xmodmap, ditto for xdotool, nothing on wayland comes close to being as good.

But since the goal is to do it on X, xmodmap is the way to go.

1
  • Cestarian, I added details, should probably mention more clearly that I was looking for permanent solution as those with xmodmap stops working by itself after some time or after I reconnect keyboard. Commented Aug 21 at 22:42
1

Remaping Menu as Super_R is complicated but possible on kernel level with udev. Here is working template.

The advantage is that this way remapped keys will work system wide on X11 or tty.

Find the number /dev/input/event* for keyboard.

sudo apt install evtest
sudo evtest

Select devices one after another with corresponding name from list and press key you want to remap. If console reacts with description - this is the correct device number. Note the event* number of the keyboard

/dev/input/event12 HCT USB Entry Keyboard

Find the value of key you want to change by pressing it. Key value is printed after (MSC_SCAN). For Menu key it is 70065.

Event: time 1755799413.562483, -------------- SYN_REPORT ------------
Event: time 1755799413.778494, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70065
Event: time 1755799413.778494, type 1 (EV_KEY), code 127 (KEY_COMPOSE), value 1

Find the ID of the keydoard. Use previously noted event12 value.

cat /sys/class/input/event12/device/modalias

Find keycode of the key you want remap to. Keys are listed in

/usr/include/linux/input-event-codes.h

Super key is named #define KEY_RIGHTMETA 126

With all information it is possible to create a file with remapping rules.

sudo vi /etc/udev/hwdb.d/70-remap.hwdb
evdev:input:b0003vC0F4p0201*
# menu to right_meta
 KEYBOARD_KEY_70065=rightmeta

It is importaint to follow rules

  1. make device name shorter with *
  2. there is a space before KEYBOARD_KEY_
  3. KEY_RIGHTMETA becomes lowercase and KEY is removed. Other tutorials write key_rightmeta with lowercase this doesn't work for me on Devuan.

sudo udevadm trigger sudo udevadm hwdb --update reboot

It is possible to add remapping rule for letter key to see if the remapping works.

# replace b with a
KEYBOARD_KEY_70011=key_a
0

I found that the problem was in the evdev file. Menu key was marked as Comp in evdev file when it should be marked as Menu. I found line with keycode 135, replaced COMP with MENU and commented alias. Now Menu key works as Super_R. Without any remapping.

state 0x40, keycode 135 (keysym 0xffec, Super_R), same_screen YES,

 $vim /usr/share/X11/xkb/keycodes/evdev
<MENU> = 135;
// alias <MENU> = <COMP>;

Instead of udev remapping I can just solve the problem that created it.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.