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.