You are not logged in.

#1 2013-10-07 02:45:27

kejingzhang
Member
Registered: 2013-09-25
Posts: 8

[SOLVED] Remapping keys using udev hwdb doesn't work on rightAlt

hi, I had posted this topic in the [ newbie corner ] subforum for days, but got no repliy. I hope I can find luck  here.

I'm trying to use udev hwdb for swapping pairs of keys ( esc, caps_lock ) and ( rightAlt , rightCtrl ) . I followed the instruction here Map Scancodes to Keycodes   with procedures describe blow. I only succeed in exchanging pair (esc, caps_lock) but failed in (rightAlt, rightCtrl).

Details of Procedures:

  1. Create an empty file under /usr/lib64/udev/hwdb.d with file name 90-custom-keys.hwdb . Add the following lines into this file.

    keyboard:dmi:bvn*:bvr*:bd*:svnDell*:pn*
     KEYBOARD_KEY_01=capslock
     KEYBOARD_KEY_3a=esc
     KEYBOARD_KEY_e038=rightctrl
     KEYBOARD_KEY_e01d=rightalt
  2. Rebuilding hwdb.bin

     udevadm hwdb --update 
  3. Testing and reboot my system

    udevadm --debug test  /devices/platform/i8042/serio0/input/input0/event0
    udevadm --debug test-builtin keyboard /devices/platform/i8042/serio0/input/input0/event0

    Parts of the testing result of the last command looks like

    device 0x1ce3890 has devpath '/devices/platform/i8042/serio0/input/input0/event0'
    device 0x1ce3890 filled with db file data
    keyboard: mapping scan code 1 (0x1) to key code 58 (0x3a)
    keyboard: mapping scan code 58 (0x3a) to key code 1 (0x1)
    keyboard: mapping scan code 129 (0x81) to key code 164 (0xa4)
    keyboard: mapping scan code 130 (0x82) to key code 166 (0xa6)
     ......
    keyboard: mapping scan code 164 (0xa4) to key code 166 (0xa6)
    keyboard: mapping scan code 216 (0xd8) to key code 152 (0x98)
    keyboard: mapping scan code 217 (0xd9) to key code 191 (0xbf)
    keyboard: mapping scan code 57373 (0xe01d) to key code 100 (0x64)
    Error calling EVIOCSKEYCODE: Invalid argument
    keyboard: mapping scan code 57400 (0xe038) to key code 97 (0x61)
    Error calling EVIOCSKEYCODE: Invalid argument
    keyboard: mapping scan code 237 (0xed) to key code 226 (0xe2)
    unload module index

    Thie last 6 lines seems to be complaining the  problem, saying that 0xe038  and 0xe01d are invalid scancodes.
    But they are scancodes of rightAlt and rightCtrl respectively, which I got from

    showkey -s

After rebooting the system with the above settings, esc works as caps_lock and caps_lock works as  esc but  rightAlt and rightCtrl has no changes.

Last edited by kejingzhang (2013-10-10 02:32:29)

Offline

#2 2013-10-07 09:55:19

plam
Member
From: Bulgaria
Registered: 2010-03-16
Posts: 37

Re: [SOLVED] Remapping keys using udev hwdb doesn't work on rightAlt

try xmodmap, I have a file .Xmodmap in my ~:

remove Lock = Caps_Lock
keysym Caps_Lock = Super_L
keysym Menu = Super_L
keycode 94 = Multi_key

This makes Caps and Menu keys act as Super (Windows key), and a extra key on my keyboard as the compose key. I posted it because you can see how to use keycodes to map keys(use xev to catch the keycodes(Right Alt is 108 on my laptop)). Then put 'xmodmap .Xmodmap' in your bashrc, or some file that is automatically run(I have it in .i3/config)

Offline

#3 2013-10-07 10:54:41

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED] Remapping keys using udev hwdb doesn't work on rightAlt

setxkbmap can be more reliable than xmodmap (at least when you run it during X session startup, like in xinitrc) and it has options for many common changes to modifier keys. See

/usr/share/X11/xkb/rules/base.lst

for a list with short descriptions. It's a long list, so search for swapescape and ralt to get to relevant options.

Edit: I don't know about the invalid argument error, but I just want to point out that you're not supposed to put custom configs under /usr/lib; they belong in /etc/udev/hwdb.d/.

Last edited by Raynman (2013-10-07 10:56:42)

Offline

#4 2013-10-09 10:17:30

plam
Member
From: Bulgaria
Registered: 2010-03-16
Posts: 37

Re: [SOLVED] Remapping keys using udev hwdb doesn't work on rightAlt

Raynman wrote:

setxkbmap can be more reliable than xmodmap (at least when you run it during X session startup, like in xinitrc)

I know it's a bit offtopic, but can you please elaborate a bit. I have never had any issues with xmodmap.

Offline

#5 2013-10-10 02:28:36

kejingzhang
Member
Registered: 2013-09-25
Posts: 8

Re: [SOLVED] Remapping keys using udev hwdb doesn't work on rightAlt

Thanks plam and Raynman for your help . Follow your hints, I succeed the swapping key task in an alternative method.

Using the command 'setkeycodes' and adding these commands into a systemd controlled service script, keymaps are exchanged as gdm started.

Here is my script and steps for doing this.

  1. Created a file with filename custom-keys.service under /etc/systemd/system. Add the  following context to the file.

     
    [Unit]
    Description=Keymap Custom
    Requires=gdm.service
    After=gdm.service
    
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/setkeycodes 1 58 
    ExecStart=/usr/bin/setkeycodes 3a 1
    ExecStart=/usr/bin/setkeycodes e01d 100
    ExecStart=/usr/bin/setkeycodes e038 97
    
    [Install]
    WantedBy=graphical.target
  2. Enable the script so setkeycodes commands will automatically executed when gdm starts

    systemctl enable custom-keys
  3. The next time you reboot your system, key changes will take effect. To test if your config works, try

    systemctl start custom-keys

Offline

Board footer

Powered by FluxBB