X11 doesn’t see keycodes above 255, so how to remap those few keys into the gaps below 255?

/usr/lib/keymap existed in raring, which worked like this:

1. Keys identification:

sudo /lib/udev/keymap input/event3
> scan code: 0xC1021   key code: zoomreset => 100%
> scan code: 0xC101F   key code: zoomin => zoom -
> scan code: 0xC1020   key code: zoomout => zoom +
> scan code: 0xC0192   key code: calc => calculator

2. Remap keys:

sudo /lib/udev/keymap input/event3 0xC1021 phone
sudo /lib/udev/keymap input/event3 0xC101F sport
sudo /lib/udev/keymap input/event3 0xC1020 shop
sudo /lib/udev/keymap input/event3 0xC0192 www

It was great, simple and quick...

xmodmap works for keys < 255 like my calculator key (code 148)

sudo evtest /dev/input/event3 
Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x46d product 0xc517 version 0x110
Input device name: "Logitech USB Receiver"
Testing ... (interrupt to exit)
> Event: time 1381940761.592647, type 1 (EV_KEY), code 140 (KEY_CALC), value 1 => calculator
> Event: time 1381940790.224658, type 1 (EV_KEY), code 420 (KEY_ZOOMRESET), value 1 => 100%
> Event: time 1381940810.928667, type 1 (EV_KEY), code 419 (KEY_ZOOMOUT), value 1 => Zoom -
> Event: time 1381940836.216678, type 1 (EV_KEY), code 418 (KEY_ZOOMIN), value 1 => Zoom +

**EDIT : I have found the solution in this ubuntuforum post.

  • Your “solution” uses an external program call “evrouter” which is not necessary – not a real solution, but a workaround. – Robert Siemer Apr 27 '14 at 18:08
  • xmodmap comes to late in the food chain, as X11 doesn’t see keycodes above 255. – Btw, I don’t use xmodmap as it knows nothing about XKB. I fiddle with the xkb config files and run setxkbmap ... for X related keyboard configuration (which this problem is not really). – Robert Siemer Apr 27 '14 at 18:51

Keymappings are still done with udev in trusty (and saucy, I guess), but the mechanism changed.

To remap a key, only one ioctl(EVIOCSKEYCODE) is necessary, but no simple program doing that exists any more. It is now internal to udev. So do this:

  1. tell udev the mappings
    1. create a file /etc/udev/hwdb.d/keyboard.hwdb
    2. write only the keyboard identifier in there and mappings you want to change (the format is like in /lib/udev/hwdb.d/60-keyboard.hwdb, where I also found those confusing identifiers for my keyboard); for example:
      keyboard:name:ThinkPad Extra Buttons:dmi:bvn*:bvr*:bd*:svnLENOVO*:pn*
    3. udevadm hwdb --update
    4. check if you see your updates via udevadm hwdb --test='keyboard:name:ThinkPad Extra Buttons:dmi:bvn*:bvr*:bd*:svnLENOVO*:pn*' (change to your keyboard id)
    5. udevadm control --reload is needed even if the man-page says otherwise – I tried it.
  2. trigger their execution (or simply reboot)
    1. with a running udevadm monitor --property you can see the effect of the next step, the --property option will reveal the remappings
    2. for my keyboard I do a udevadm trigger --verbose --sysname-match=event6 --action=add The “add action” is important, because “change” events are ignored in the current keyboard rules.
    3. in your case a --sysname-match=event3 would do it, but you can play around with it via these three:
      • udevadm trigger --dry-run --verbose shows you all devices
      • inspire you fantasy for matcher building with udevadm info /sys/devices/platform/thinkpad_acpi/input/input12/event6 or whatever your device
      • udevadm trigger --help will give you hint how to reduce the next trigger dry-run
| improve this answer | |
  • What about step # 1 of the OP's Info? – Karthik T Sep 11 '15 at 10:09
  • @KarthikT, I never used that keymap tool. As explained in 60-keyboard.hwdb you can use evtest to get scan codes. – Robert Siemer Sep 11 '15 at 23:17
  • I see, is that as close to the metal as it gets? I am trying to do this in superuser.com/questions/970279/using-a-gaming-keyboard-on-osx/970338 and evtest returns the same code for all the keyboard modifiers, so cant exactly remap just one.. – Karthik T Sep 12 '15 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.