(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!
ChatGPT isn't wrong - this sounds like what you need: https://pypi.org/project/zero-hid/.
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.
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.
On the hardware side, it probably has what you need (and more).
Using Zig to Unit-Test a C Application (2023) - https://mtlynch.io/notes/zig-unit-test-c/
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 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.
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.
2 arduinos with a serial link between them.
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...
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.
> (I would use it to use a laptop keyboard on a headless computers).
Are you sure you need such a device? If this is to occasionally manage that headless system, wouldn’t a Remote Desktop connection work fine?
You’re mentioning a Mac Mini and a MacBook elsewhere, so https://support.apple.com/en-gb/guide/remote-desktop/apdf49e... might be sufficient for your needs.