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.
Looks like a perfect use case for usbproxy (https://github.com/usb-tools/USBProxy-legacy)
It‘s 2020 and a keyboard that is connected via USB still doesn’t communicate it‘s layout to the computer. That‘s so stupid it‘s almost funny.
The worst part is that it’s in the USB-HID specs I think.
At least Sun keybords from 10-20 years ago had such a data field and the SunRay thinclients switched to the right layout automatically.
why raspberry ? I think some small arduino could be enough
tldrbl: he didn’t have the arduino and shield, he did have the rpi, check out his build log.
I must admit that I’ve been in need of an extra USB keyboard and I’ve been pondering using a raspberry pi, or a STM32F4 board to convert PS/2 to USB.
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.
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.
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.
A Pi seems overkill here. Why not get a microcontroller that supports a keyboard firmware like QMK and wire it up to the keyboard’s matrix internally?
Read the build log.
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.
Yeah! Where’s the 555 timer chip!
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.
Make a 1:1 mapping and add a logger… what? Am I a bad person or it’s just friday?
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.
https://www.randyrants.com/category/sharpkeys/
SharpKeys gets a Mac keyboard working very nicely on Windows. Pause/Break key isn’t 100%, something about its scan code is unlike most other keys.
I think F10 can’t be remapped either but it works as F10 on both mac and Windows.
Not trying to dismiss the hack, just passing on info.
It does exist, bCountryCode, but apparently nobody supports it on either the OS or hardware side really.
https://stackoverflow.com/questions/39388141/send-language-layout-from-usb-hid-keyboard/39814973