Hardware Keymapper Routes Through Raspberry Pi

There are a lot of keyboards to choose from, and a quick trip through some of the forums will quickly show you how fanatical some people can be about very specific styles or switches. [Crdotson] doesn’t seem to be too far down the rabbit hole in that regard, but he does have a keyboard that he really likes despite one small quirk: it’s built for Mac, and some of the modifier keys aren’t laid out correctly for Windows. Since Windows has limited (and poor) options for software keymapping, he took an alternative route and built a keymapper in hardware instead.

The build uses a Raspberry Pi as a go-between from the keyboard to his computer. The Pi watches the USB bus using usbmon, which allows inspection of the packets and can see which keys have been pressed. It then passes those keypresses through to the computer. His only modification to the keyboard mapping is to swap the Alt and Super (Windows) keys for his keyboard of choice, although using this software would allow any other changes to be made as well. Latency is only on the order of a few microseconds, which is not noticeable for normal use cases.

While we have seen plenty of other builds around that can map keyboards in plenty of custom ways, if you don’t have the required hardware for a bespoke solution it’s much more likely that there’s a Raspberry Pi laying around that can do the job instead. There are a few issues with the build that [crdotson] is planning to tackle, though, such as unplugging the device while a key is being pressed, which perpetually sends that keystroke to the computer without stopping. But for now it’s a workable solution for his problem.

19 thoughts on “Hardware Keymapper Routes Through Raspberry Pi

  1. I’d like to do the reverse. I don’t own an Apple Keyboard but I’m regularly tasked to boot on Apple machines and that’s a PITA. I wonder whether a custom mechanical keyboard with some OSS firmware would be able to switch from a Windows/Linux layout to an Apple one.

    1. sure, you could easily integrate this functionality into any of the usual open source keyboard firmware like TMK/QMK.

      The only real difference between the two is that the alt and windows keys usually need to be flipped to properly match the layout of command and option, and you could easily add a toggle (heck, you could implement this on any keyboard just by cutting traces and bridging them two different ways with a switch).

      that said, if you don’t want to build a custom keyboard, mac OS will happily let you remap the ctrl/windows/alt keys in keyboard settings, and since it remembers per-keyboard, you only have to do it once per device.

      and, although it’s more of a pain, you *can* remap keys in windows by fiddling with the registry.

      1. Thanks for your constructive feedback, it’s much appreciated. I’m going to check out QMK and TMK (never thought there could be so much solutions for such a narrow problem !).

        I’ve got a PoS mechanical keyboard on my hands are I’m in a lockdown(ed?) country so it will makes for a good project. Heck Know I’m thinking about it the damn thing got more than 104 keys so I may only have one keympa which includes PC keys + the one ore two (Apple and eject keys comes to mind) special Apple keys.

  2. terrible nitpicking here but how is putting a computer between your computer and the keyboard taking “an alternative route” by building “a keymapper in HARDWARE instead”?

    routing the keyboard matrix to a breadboard were you can map your keys however you want with jumper cables is a keymapper in hardware. What [Crdotson] did is at the farthest other “end” of the spectrum with microcontrollers and what not in between.

    1. You’re right, probably more properly, “as a bump in the wire on the USB bus”, but contrasted with, “I told my Windows machine to remap the keys in software.” But you’re right, it’s just software on the Pi. From the perspective of the Windows box, though, it’s a hardware fix. :)

      And yeah, the PI4 is HUGE overkill for this — but I had one lying around not doing anything else, and frankly it’s cheaper than the hardware USB-to-USB remappers that are available either pre-built — or even cost of parts once you buy a microcontroller and USB shield. Particularly because you don’t need a power supply, since it gets power from the host’s USB bus as it feeds it HID USB packets.

      Also, I did try the Windows registry hacks (via PowerToys, in this case) and the problem was that every so often the machine would get confused and revert back to the normal behavior for the Alt key. I suspect that other keys wouldn’t be as much of a problem as the “special” Alt/Windows modifier keys, but I don’t know for sure. This is certainly something that should be fixable in software, or more elegantly by replacing the controller on the keyboard, but it works well.

  3. Being a Linux guy, just eliminate the Windows machine entirely and just leave the RPI connected to the keyboard ;) Ha. That said, neat to use the ‘parts you have on hand’ and come up with a solution to a particular problem.

Leave a Reply to sqelchCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.