Is there a way to pass keyboard or joystick input to a phone through a computer? I use my phone to emulate old games, but using the touch screen for input hurts my fingers and gives me cramps. 

Is there a way for me to connect my phone to a computer then pass input from a keyboard or a joystick attached to the computer as if I had connected them directly to the phone?
Yes.

This app is open source (but old and limited in features), provides a web interface to use in your computer browser over the same (W)LAN: https://play.google.com/store/apps/details?id=com.marcosdiez.keyboard.latin

There's other apps to remote control your phone that are more capable (but not all are open source);

https://play.google.com/store/apps/details?id=com.sand.airdroid