20

My Logitech R400 presenter sends the following key codes:

keycode 112 (keysym 0xff55,  Prior) [page up]
keycode 117 (keysym 0xff56,   Next) [page down]
keycode  60 (keysym   0x2e, period)
keycode  71 (keysym 0xffc2,     F5)
keycode   9 (keysym 0xff1b, Escape)

Basically, I want to use this presenter to remotely control Banshee, so I'd like to remap Prior to B, Next to N, and so on.

How can I change the keymap for this device only (as I certainly don't want to remap those key codes globally)?

  • AFAIU "slave pointer" means it's a mouse, not a keyboard. You can't load a keymap onto a mouse. Are those really the only devices present in xinput list? – Marius Gedminas Oct 22 '11 at 19:01
  • @MariusGedminas I had to go through the /dev/input/eventX devices and event5 was the presenter, so it seems to be a "keyboard" after all. – htorque Oct 22 '11 at 19:25
15

I never did that but I think you need to create a keymap file in /lib/udev/keymaps/ and add a rule for your device to /lib/udev/rules.d/95-keymap.rules


Details:

  • An udev keymap maps scan codes to key codes, so you need to find both to create the keymap file. To find the scan codes run the following and press the buttons on the device:

    sudo /lib/udev/keymap -i input/event5
    

    You might need to try different numbers for event*. The output should look like this:

    scan code: 0x70037   key code: dot
    scan code: 0x70029   key code: esc
    scan code: 0x7003E   key code: f5
    scan code: 0x7004B   key code: pageup
    scan code: 0x7004E   key code: pagedown
    

    A list of key codes can be found here.

    Now create the keymap file (I'm storing it as /lib/udev/keymaps/logitech-r400):

    0x70037 brightnessdown
    0x70029 brightnessup
    0x7003E brightnessdown
    0x7004B brightnessup
    0x7004E brightnessdown
    

    Doesn't do anything useful - just a test to easily see if it works.

  • To test the new keymap temporarily, run:

    sudo /lib/udev/keymap input/event5 /lib/udev/keymaps/logitech-r400
    

    which should result in output like this:

    Remapped scancode 0x70037 to 0xe0 (prior: 0x34)
    Remapped scancode 0x70029 to 0xe1 (prior: 0x01)
    Remapped scancode 0x7003e to 0xe0 (prior: 0x3f)
    Remapped scancode 0x7004b to 0xe1 (prior: 0x68)
    Remapped scancode 0x7004e to 0xe0 (prior: 0x6d)
    

    The buttons should now change the brightness.

  • If you want to make that change permanent, you need to add an udev rule to /lib/udev/rules.d/95-keymap.rules that applies the keymap file to the device.

    1. Open the file: gksudo gedit /lib/udev/rules.d/95-keymap.rules
    2. At the bottom of the file, but before the LABEL="keyboard_end" line, add:

      ENV{ID_VENDOR}=="Logitech*", ATTRS{idProduct}=="c52d", RUN+="keymap $name logitech-r400"
      
    3. Save, close, and after a reboot the buttons should change the brightness.

  • Oh how could I forget about that (/lib/udev/keymaps/zepto-znote was contributed by me :D). I will later add more about how I made it work to your answer. – htorque Oct 22 '11 at 19:24
  • Just wanted to add to this answer that you can zero in on what "eventX" your keyboard might be by running /lib/udev/findkeyboards. That will list all the currently attached keyboards so you don't have to try so many. The logitech r400 showed up as "USB keyboard: input/event11" for me. – jat255 Aug 15 '12 at 19:26
  • Nice answer, but how do I discover the ID_VENDOR and idProduct to use? I tried /sys/class/dmi/id/sys_vendor and /sys/class/dmi/id/product_name but it didn't work. – PutzKipa Oct 25 '12 at 13:22
  • 2
    /lib/udev/keymap and /lib/udev/findkeyboards no longer exist on 13.10. forum.ubuntu-fr.org/viewtopic.php?id=1395051 says to use evtest instead. – Stéphane Gourichon Nov 4 '13 at 10:07
  • 6
    Hello @htorque, could you update the answer to the new way ? In Ubuntu Trusty all these files don't exist anymore. You are the only one I have seen on the net having the same isue. – londumas Mar 31 '14 at 21:39
4

I'm on Ubuntu 16.04. I made a guide here

Detecting with evtest

sudo evtest

Look at the device list :

/dev/input/event0:  Lid Switch
/dev/input/event1:  Power Button
/dev/input/event2:  Sleep Button
/dev/input/event3:  Power Button
/dev/input/event4:  AT Translated Set 2 keyboard
/dev/input/event5:  Video Bus
/dev/input/event6:  USB Optical Mouse
/dev/input/event7:  AlpsPS/2 ALPS DualPoint Stick
/dev/input/event8:  AlpsPS/2 ALPS DualPoint TouchPad
/dev/input/event9:  Logitech USB Receiver
/dev/input/event10: Logitech USB Receiver
/dev/input/event11: HDA Intel PCH Dock Mic
/dev/input/event12: HDA Intel PCH Headset Mic
/dev/input/event13: HDA Intel PCH Dock Line Out
/dev/input/event14: HDA Intel PCH Headphone
/dev/input/event15: HDA Intel PCH HDMI/DP,pcm=3
/dev/input/event16: HDA Intel PCH HDMI/DP,pcm=7
/dev/input/event17: HDA Intel PCH HDMI/DP,pcm=8
/dev/input/event18: Integrated Webcam
/dev/input/event19: Dell WMI hotkeys
Select the device event number [0-19]: 9
Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x46d product 0xc52d version 0x111
Input device name: "Logitech USB Receiver"

Took the first "Logitech USB Receiver", here it has event id 9.

Testing ... (interrupt to exit)

OK now evtest wants inputs, just click on the Logitech remote buttons, I got this (simplified):

[>] value 7003e (KEY_PRESENTATION)
[>] value 70029 (KEY_PRESENTATION)
[ ] value 70037 (KEY_DISPLAYTOGGLE)
 <  value 7004b (KEY_PAGEUP)
 >  value 7004e (KEY_PAGEDOWN)

Note: I discovered after that clicking multiple times on [>] was giving 7003e, then 70029, then 7003e, etc. I don't know why.

Modifying udev conf

Now that we have input codes, let's have a look at udev conf:

sudo gedit /lib/udev/hwdb.d/60-keyboard.hwdb

Search for "R400" and replace presentation & displaytoggle by what you want, playpause & stopcd arrow keys:

# Logitech Presenter R400
evdev:input:b0003v046DpC52D*
 KEYBOARD_KEY_070029=playpause    # bottom  left [>] was "presentation"   
 KEYBOARD_KEY_07003e=playpause    # bottom  left [>] was "presentation"  
 KEYBOARD_KEY_070037=stopcd       # bottom right [ ] was "displaytoggle"

As previously noted, because 07003e & 070029 are the same button, I gave them the same output up key. The 7004b & 7004e does not appear here by default, maybe because they are native PAGEUP & PAGEDOWN inputs and not related to "Logitech Presenter R400". Let's add them:

 KEYBOARD_KEY_07004b=previoussong #    top  left  <
 KEYBOARD_KEY_07004e=nextsong     #    top right  >  

Here is my final conf:

 KEYBOARD_KEY_07004b=previoussong #    top  left  <
 KEYBOARD_KEY_07004e=nextsong     #    top right  >
 KEYBOARD_KEY_070029=playpause    # bottom  left [>] was "presentation"
 KEYBOARD_KEY_07003e=playpause    # bottom  left [>] was "presentation"
 KEYBOARD_KEY_070037=stopcd       # bottom right [ ] was "displaytoggle"

Reloading (new) rules

sudo udevadm hwdb --update

Then by using the same event id we chose before, here event id 9:

sudo udevadm trigger /dev/input/event9

You can check this new mapping in a web browser, for example:

$('body').on('keydown', function(e){ console.log(e.key) })

That gave me:

[>] ArrowUp
[ ] ArrowDown
 <  ArrowLeft
 >  ArrowRight
  • I have made some small improvements in your original logitech-r400-remap.md guide from GitHub. Please feel free to either change them or edit them into your GitHub webpage if you want (no attribution to me is necessary). Your answer was downvoted because it was a link only answer in my opinion, so I also undid the downvote. – karel Jan 26 '17 at 12:33
  • The downotes have been removed, so now your answer has the opportunity to be considered on its own merits like any other answer here. – karel Jan 27 '17 at 8:18
  • 1
    Used your guide. Worked like a charm : ) – Costa Feb 26 at 5:27

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.