(I would use it to use a laptop keyboard on a headless computers).
I am looking for an easy solution, it does not have to be the cheapest.
ChatGPT points me to Arduino, but as far as I can see, there's no arduino with 2 usb ports. It also points me to Raspery pi zero, but that's a computer, not a microcontroller, so not sure if it's suitable.
If anyone with experience can give me some pointers, it would be greatly appreciated!
https://www.digikey.com/en/products/detail/texas-instruments...
Alternatively, the newer ESP32-S3 boards (<$6 each) have dual USB-C interfaces, so you could do it with only one (smaller) card instead of two. Development might take longer though.
https://www.amazon.com/dp/B0CN4789XC
If you want to allow a network connection between the two computers, you could load soft-KVM software on each, and go from there.
https://goinglinux.com/open-source-cross-platform-kvm-softwa...
https://xairy.io/articles/thinkpad-xdci
The only security barrier that macOS implements against this kind of attack is, that you must manually confirm after you connected that "keyboard", for system to enable it.
People even suggesting using two Ardinos which each have a USB serial chip on board
You could do something similar with a couple of Raspberry Pi's or RPI nanos. It doesn't really matter as both can be configured as USB devices and to access their GPIO ports.
The trick is getting them to act as a USB device and then to have them send data over the GPIO ports.
Fortunately I don't think either of those should be super hard.
If not: You need something that can act as a usb "device" (the "host" and "device" sides of a usb connection are very different). A search for "usb keyboard emulator" turns up a lot of projects in that area. I'm not sure you're going to get much simpler than a pi-zero or teensy, unless you can find someone selling a pre built device that meets your needs.
If you're lucky, your laptop has a usb port that can be configured to take the "device" role instead of the usual "host" role. In that case you could probably build a software-only solution using the Linux usb "gadget" framework to make that port act like a keyboard when attached to the target's usb port.
On the hardware side, it probably has what you need (and more).
ChatGPT isn't wrong - this sounds like what you need: https://pypi.org/project/zero-hid/.
I am unfamiliar with Raspberry pi, but if my understanding is correct, it's running a real os. So I would need to send it a command to actually shut down every time I want to remove the usb device. More generally, having a general purpose OS on the little device seems overkill for that use case, no?
You could use an rpi pico. It has a usb port and there is a software hack to bit bang a second usb port, iirc.
To go one step higher, I am trying to control a mac mini from the keyboard of a macBook.
But yes, it's overkill for an overkill solution. Buying another keyboard may be easier.
After each newline, you are the "device" in the middle that unplugs the USB from the source computer and plugs it in to the destination computer.
Now we want to automate the middle, but without networking. How to do that?
See also Logitech Flow keyboard (and mouse). After each batch of commands, communicate via the shared clipboard.
You also might want to use optical isolators between these microcontrollers, instead of wiring them directly. Just connecting grounds might be wrong, because different computers might have different grounds.
It might be simpler to get 2 microcontrollers and establish a communication link between them. Something like Arduino (Nano or even smaller third party boards), or Teensy would be suitable for this kind of setup.
2 arduinos with a serial link between them.
Using Zig to Unit-Test a C Application (2023) - https://mtlynch.io/notes/zig-unit-test-c/
The reason it is not simple is USB is asymmetric. There’s one host and multiple clients. And computers are approximately always built as hosts.
But if you are going to add hardware, a pair of usb network adapters (wired (or wireless)) has the same architecture.
And you won’t have custom software below the application layer. Good luck.
You're going to need software on the laptop to gather the input. That seems necessary. You're not going to invent a purely hardware based solution here.
Given that, I'd abandon your starting requirement of needing two usb device ports. That doesn't seem to help you out here, doesn't actually buy you much.
I'd look at the field of existing software out there that can ship input between systems. Use ethernet, wifi, or BT for connectivity if possible (perhaps via usb-ethernet adapters which are very cheap!), and if absolutely required you can build a little rpi-zero with a usb-gadget to act like a virtual keyboard. https://github.com/input-leap/input-leap https://github.com/feschber/lan-mouse https://github.com/lkundrak/btkbdd
The one carve out I'd make: if you want to minimize the configuration at the target device, it ought be possible to make a rpi0 device that outputs a usb-gadget keyboard. Continue using one of these IP based software systems to send input to the rpi0, then usb-gadget it out to the target device.
The btkbdd project also might be up your alley: if the target system has bluetooth or can have a (very cheap!) usb<->bluetooth adapter added, making the laptop just send a bluetooth HID to the other device is probably one of the lowest configuration most standard paths available for this work.
I am fine with having quite a bit of configuration on the target device (I am fine with configuration on both sides).
> it ought be possible to make a rpi0 device that outputs a usb-gadget keyboard
I like very much the idea of being able to make the host side (macBook) appear as a usb-gadget keyboard. That way I would just need to plug a single usb cable between the 2 computers. Could you give me a few pointers to get started, to do this on macOS?
I’m curious about your use case. You have a server that you can’t ssh/vnc/rdp into, it has an open usb port, and using an $8 keyboard is a no-go?
Edit: If you ignore all the hacking language, it kind of looks like an O.MG Plug might accomplish what you’re looking for. https://shop.hak5.org/products/omg-plug