Remap "Caps Lock" to "Shift" (Missing key on USB RF Remote, "Jump to Letter" feature)

  • I have a couple of (identical) USB RF Remotes for my various Kodi-using devices, one on Android and another on LibreELEC (an RPI3). These remotes usually get sold under a product name like "MX3", and an unfortunate oversight in their design is that they have no SHIFT key, only CAPS (Lock). This is a shame since we make frequent use of the "Jump to letter" feature (press shift+Letter to jump to that letter in Library lists).


    I tried to "fix" this by using the Keymap Editor add-on inside Kodi to remap the CAPS key's keycode to the shift feature, which made the file keymaps/gen.xml:

    Code
    1. <keymap><global><keyboard><key id="61657">shift</key></keyboard></global><videos><keyboard><key id="61657">shift</key></keyboard></videos></keymap>

    However, even when fully rebooting the device running Kodi (be it that running Android or that running LibreELEC), the key still functions regardless as caps lock.


    I was able to modify things to my satisfaction on my Android setup by remapping the keyboard at the OS-level. I am however struggling to work out how I am supposed to do this in LibreELEC.


    I have spoken in #kodi and #libreelec on Freenode IRC but so far haven't been able to work out quite how next to proceed. The seemingly best idea for now is from "vpeter" who thinks it might be possible to use udev and the hwdb akin to this article on the Arch Wiki, but due to the lack of peripheral tools inside LibreELEC it is difficult to translate the information in the Wiki into a form useful for this case. Curiously, lsusb doesn't appear to list my RF adapter, and the only information I've so far gained is an excerpt from my dmesg.

    Code
    1. [ 2.155495] input: MemsArt MA144 RF Controller as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/0003:0C45:5101.0001/input/input0
    2. [ 2.212174] hid-generic 0003:0C45:5101.0001: input,hidraw0: USB HID v1.10 Keyboard [MemsArt MA144 RF Controller] on usb-3f980000.usb-1.2/input0
    3. [ 2.216507] input: MemsArt MA144 RF Controller as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.1/0003:0C45:5101.0002/input/input1
    4. [ 2.216805] hid-generic 0003:0C45:5101.0002: input,hidraw1: USB HID v1.10 Mouse [MemsArt MA144 RF Controller] on usb-3f980000.usb-1.2/input1
    5. [ 2.221592] input: MemsArt MA144 RF Controller as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.2/0003:0C45:5101.0003/input/input2
    6. [ 2.279802] hid-generic 0003:0C45:5101.0003: input,hidraw2: USB HID v1.10 Device [MemsArt MA144 RF Controller] on usb-3f980000.usb-1.2/input2


    Since this is getting rather involved, I decided it would be best to open a forum thread, and then hopefully not only can I come to a solution, but also document it publicly in the process.

    I look forward to any input any of you may have, and am willing to clarify anything as needed.

  • "vpeter" in IRC was able to guide me towards the solution, so I'll try my best now to summarise and share.


    Prerequisite: Install the "System Tools" add-on from the LibreELEC repository.

    Pre-reading: usb - How to find the .hwdb header of a general input device? - Ask Ubuntu and Map scancodes to keycodes - ArchWiki

    1. In lsusb the line I wanted, despite appearances, was Bus 001 Device 004: ID 0c45:5101 Microdia.
    2. Search for the manufacturer id 0c45 using # find /sys -name *modalias | xargs grep -i 0C45 (capital letters)
    3. From evtest it's clear that the device which presents keyboard keys was /dev/input/event0, so the part of step 2's output we need is input:b0003v0C45p5101e0110*
    4. To get the scancode, run # systemctl stop kodi then run evtest again, pressing the Caps Lock key to yield the ID "70039" (you want the code from the "MSC_SCAN" line which comes as part of the block of events that occur at the moment of pressing. (You need to stop kodi, otherwise it will block the ability to monitor these events)
    5. I create the file /etc/udev/hwdb/99-mx3.hwdb with the following contents*, to map this scancode to the Left Shift key:
    6. To apply the changes, run # systemd-hwdb update then # udevadm trigger then of course # systemctl start kodi to get back into business.

    *file contents, step 5:

    Code
    1. evdev:input:b0003v0C45p5101e0110*
    2. KEYBOARD_KEY_70039=leftshift

    It's also possible to test things by running # udevadm info /dev/input/by-path/*-kbd | grep KEY and pressing the key in question.




    I think this should be sufficient for someone else in a similar situation to be able to reproduce what I've done. I'll re-read this later to double-check, but otherwise any feedback would be appreciated.

  • It seems that something has changed since I made this posting. Now, despite the "left shift" events showing up in evtest, "shift"+letter does NOT result in jump-to-letter.


    I discovered this on a freshly-installed 8.2.4 ODROID-C2, but the problem was also present on a not-yet-updated RPI3 on 8.2.1, so at some point between September 4th 2017 and AT LATEST 8.2.1 there has been some sort of change which makes this no longer work.


    I will investigate further, but would appreciate any pointers or suggestions.