Mega or Uno as keyboard emulator (USB or PS2)

I have a Raspberry Pi running a simple program using Qt. I, for the life of me, cannot figure out how to get my Qt program to read or write to the Pi's GPIO pins, which it needs to do in order to interact with my Mega.

My new approach is to have the Arduino emulate keystrokes and send those to the Pi. That, too, has proven to be more difficult than I had originally anticipated. My Mega is already controlling a touch screen, so any approach that requires me to change the firmware will probably introduce more problems than it will solve.

I bought these USB socket connectors, thinking I could follow the instructions from this video and make a shield or something, but the library seems a bit dated and requires an older version of the IDE to work, which makes me nervous as well.

Is there some obvious solution that I am missing here? If not, I may have to do the custom firmware solution on a Nano and have that act as a go-between for the Mega and the Pi, which sounds like the stupidest, most inefficient solution I can come up with.

Thanks in advance for any advice.

Regarding USB, you might look at this: Note that can only be done with the boards (such as the official ones but some clones also) that have the ATmega16U2 (or similar) USB-serial chip. You can't do it if your board has a CH340, FT232, CP2102, or similar USB-serial chip.

But if you want to have simple USB keyboard emulation I recommend just buying a Pro Micro or Leonardo.

PS2 would probably be easier with the Mega or Uno. I remember seeing a library but it might have been for using a keyboard as an input device for the Arduino board rather than using the Arduino to emulate a PS2 keyboard.

Yeah, I already gave up and just ordered a Pro Micro. Decided it wasn’t worth the stress trying to make it work with the Mega.

If you connect Pi GPIO (3.3V) to Mega pins (5V), you must use logic level converters.