Record and replay controlls

I would like to be able to record the inputs from a joystick and be able to play them back later, what would be the best way to go about this?

The question has come up before. Here is one relevant discussion.