9

I'm trying to make slider on MS keyboard working, but still it doesn't.

What I've tried already:

in /etc/udev/hwdb.d/61-keyboard-local.hwdb

keyboard:usb:v045Ep00DB*
  KEYBOARD_KEY_c022d=up
  KEYBOARD_KEY_c022e=down

and

evdev:input:b0003v045Ep00DB*
 KEYBOARD_KEY_c022d=up
 KEYBOARD_KEY_c022e=down

following

sudo udevadm hwdb --update
sudo udevadm control --reload

and reboot didn't do anything.

In /lib/udev/keymaps/microsoft-ergonomic-keyboard

0xC022D 0xC1 # Zoom Up which we wish to be Scroll up
0xC022E 0xC2 # Zoom Down which we wish to be Scroll down

and reboot didn't do anything.

In /etc/X11/xorg.conf.d/10-keyboard.conf

Section "InputDevice"
    Identifier  "Keyboard1"
    Driver      "evdev"
    Option      "Device" "/dev/input/event9"
    Option      "event_key_remap" "418=185 419=186 423=101 425=156 421=157"
EndSection

and reboot didn't do anything.

What I have is

> sudo evtest /dev/input/event9             
Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x45e product 0xdb version 0x111
Input device name: "Microsoft Natural® Ergonomic Keyboard 4000"
...
Testing ... (interrupt to exit)
Event: time 1478692111.766327, type 4 (EV_MSC), code 4 (MSC_SCAN), value c022d
Event: time 1478692111.766327, type 1 (EV_KEY), code 418 (KEY_ZOOMIN), value 1
Event: time 1478692111.766327, -------------- SYN_REPORT ------------
Event: time 1478692111.886318, type 4 (EV_MSC), code 4 (MSC_SCAN), value c022d
Event: time 1478692111.886318, type 1 (EV_KEY), code 418 (KEY_ZOOMIN), value 0
Event: time 1478692111.886318, -------------- SYN_REPORT ------------
Event: time 1478692112.678287, type 4 (EV_MSC), code 4 (MSC_SCAN), value c022e
Event: time 1478692112.678287, type 1 (EV_KEY), code 419 (KEY_ZOOMOUT), value 1
Event: time 1478692112.678287, -------------- SYN_REPORT ------------
Event: time 1478692112.798370, type 4 (EV_MSC), code 4 (MSC_SCAN), value c022e
Event: time 1478692112.798370, type 1 (EV_KEY), code 419 (KEY_ZOOMOUT), value 0
Event: time 1478692112.798370, -------------- SYN_REPORT ------------

So the slider works, evtest can see events, but xev doesn't show anything. Is there anything else I can try to make it work in 2016?

I'm using Linux Mint 18 Sarah with 4.4.0-34-generic kernel.

phk
  • 5,953
  • 7
  • 42
  • 71

1 Answers1

9

Background: Your keyboard is a HID USB device, and the kernel properly recognizes the HID USB events for your slider keys, and translates them to keycodes (KEY_ZOOMIN and KEY_ZOOMOUT). So in that respect, it's already "working": You can receive the events and do something useful with it.

However, the X keyboard translations only supports keycodes up to 255 (see this answer, it's a limitation of the X protocol). So you can't convert them to X keysyms. (And maybe that's not what you want, anyway, because zooming is usually handled by mouse button events in applications, namely button 4 and 5. So even if you did convert it to keysyms, they wouldn't zoom in or out).

But from what you tried to do, it looks like you want to remap them to up and down keys, identical to the arrow up and down keys that are already available as other keys on the keyboard.

  1. As mentioned in the answer already linked, to enable X to remap keycodes greater than 255, somebody created a patched variant of the X evdev driver. So you need to compile and install this patched variant, and then the option event_key_remap will be recognized. It won't be recognized by the standard evdev driver, so it's no surprise that your xorg.conf entry didn't do anything.

    That's probably the cleanest method.

  2. In the process of taking over all of Linux, systemd apparently also has now its own hardware database and can overwrite keyboard mappings. I'm not really sure on which level of the kernel this is working, so I don't know if it will help at all, and the format for the "hardware database" doesn't seem to be documented. So I can't help you much in this respect.

    However, the format for matching seems to have changed, so maybe you have more luck if you include the bus number, as described.

    Edit: Reading the kernel source, I found that each input device has its own scancode (hardware dependend, up to 8 bytes, though in many places only 1/2/4 bytes in the kernel are transferred) to keycode (what you see with evtest) translation mappings. Large code values can be set and get with the EVIOCGKEYCODE_V2 and EVIOCSKEYCODE_V2 ioctls on the device. A general tool similar to xmodmap or loadkeys/dumpkeys doesn't seem to exist, though some IR receiver related tools apparently use these ioctls. If that's how the systemd database works, a more flexible alternative would to be to use such a tool in a udev rule (also simpler for testing). I've written a quick C program to dump the mapping, maybe I should put it on github ...

  3. In principle, you can already process the events with your own programs or scripts and do anything you'd like to do. For example, run evtest on it, parse the output with a bash script, and invoke xdotool with button presses of 4 or 5 to get the same effect as a mouse scrollwheel for your slider buttons. Etc., pp. (There was a stackexchange question with a rudimentary script for a similar purpose, but I can't find it right now. If necessary, I can search some more).

phk
  • 5,953
  • 7
  • 42
  • 71
dirkt
  • 32,309