I use the Workman keyboard layout, and I've written about that in blog posts in the past. It's lovely for my personal use, but since I haven't used Qwerty consistently in more than 18 months, I have forgotten how to type on it. This makes it much less convenient if I need to type more than a few words on somebody else's computer, or a managed system that I can't install the layout on. Lugging my own keyboard around with me won't do any good, because the keyboard layout is managed in software, not hardware.
For a while I've been thinking about a hardware device that I can carry around with me, that I can plug a keyboard into, and then plug the device into the USB port of a computer. The device would pretend to be a keyboard, and keys typed on the real keyboard would be remapped by the hardware, allowing me to take my layout anywhere without needing to configure any software on the target computer.
For example, when I press the key T (or where the key T should be on the keyboard), the hardware device will intercept and read this keystroke, figure out which letter it is based on the Workman layout, find where that letter would be on the Qwerty layout, and send the Qwerty key position to the target computer.
Has somebody already made this?
As far as I can tell, no. But if somebody has, pleasepleaseplease let me know since it would save me a lot of work reading about USB technicalities and figuring out which hardware will actually work, since I can use the same hardware that they used!
A detour: USB modes
Whatever hardware I use, the key factor of whether it's usable is whether it has USB support. The device needs to accept USB keyboard input and provide USB keyboard output. If it can do that, then writing the code to connect the two is probably the easy part.
The USB protocol is complex. I can't build a keyboard layout remapper using just electronic components; I'll have to use some kind of microcomputer or microcontroller. In particular I'll be investigating the Raspberry Pi microcomputer and the Arduino microcontroller.
Finally, USB can operate in either -host mode- or in -otg mode-. When a computer uses host mode, you can connect peripherals to it. When it uses otg mode, you can connect it as a peripheral to something else. In my case, I need to have one USB port in host mode and a different USB port in otg mode. I cannot use a hub to mix types.
I'm not 100% sure, but I think USB type C may be able to be configured as either type. However I do still need to connect it to USB type A stuff in both directions.
Can I use a Raspberry Pi?
A Raspberry Pi is a Linux computer, so all models of it absolutely supports USB peripherals (host mode). I already own a few of the Raspberry Pi models. However, only some models support otg mode.
The Raspberry Pi Zero has one USB data port which can be configured to either otg mode or host mode at boot time. This isn't suitable for me since I need to connect 2 cables at the same time. (Though, if I were using a physical bluetooth keyboard for this project, then I could run the Pi in otg mode and connect the keyboard through bluetooth and this would work.)
As far as I can tell, all USB hubs sold for the Pi Zero actually jack in to the otg port, they don't create new USB ports. So you can't use this and otg mode at the same time.
The Raspberry Pi model A and its siblings also support otg mode. Like the Zero, they only have one port, so they're not suitable for me.
The Raspberry Pi model 4 B has 4 type-A USB ports which can only be used in host mode, and also 1 USB type C port which is normally used for power input which can additionally be configured to otg mode. If the Pi's power draw is acceptable, then this would work for my project!
However, due to a global chip shortage, it's literally impossible for me to get a Pi 4.
A Raspberry Pi would probably take about 15 seconds to start up, which isn't totally ideal, but would be good enough for this project.
Can I use an Arduino?
The Arduino connects to a computer using its USB type B port, acting as a peripheral (like otg mode). So we just need a way to make it also act as a host.
There *appear* to be USB host shields (a shield is the Arduino name for a hardware expansion). Whether they actually work, or work well, I do not know. It seems easier to obtain these than it is to obtain a Raspberry Pi 4.
I already have an Arduino Uno, and I think it's currently possible to purchase an Arduino if I need a different model. I do not understand the ecosystem or the different models.
Can I use a Teensy microcontroller?
When making a totally custom keyboard, James Stanley used a Teensy as the microcontroller, connecting switches to its digital inputs and sending the output through the micro USB cable (otg mode) using QMK as the firmware.
The PJRC store sells a "USB Host Cable" for the Teensy board, the connections on which are exactly what I'm looking for. It says that it allowed connecting a USB device to the Teensy, and that the "Teensy 4.0 has USB host capability on bottom-side pads". So, if I understand everything correctly, I believe that I can use this host cable and the regular socket on the Teensy at the same time.
I have no idea whether these assumptions are correct, though. If I decide to acquire a Teensy I'll do some emailing first to make sure I can use both cables at the same time.
So what next?
I'm planning to visit my parents to pick up my old electronics stuff, most notably my Arduino Uno, and see if I can get it to send a fixed sequence of keys to the computer. If I can do this, then I'll start browsing for a USB host shield that looks suitable, and that should be the difficult part of this project all done!
If I'm successful at making the hardware remapper I'll likely try to design a pretty wooden or acrylic box to put things in. I don't have access to a 3D printer, so I'll have to use woodworking tools or off-the-shelf acrylic boxes.
If this gets any further through the planning phase then I'll make a follow-up post. See you then!