To store inputs, you would push each input into an array as you enter them. The format is up to you, as well as what to do with the history of inputs after you have them stored.
I had an old example that stored coordinates here. dropbox.com/s/1vi6kp5p7lcn30n/undo_example.c3p
I know you said coordinates won't work for your system, but the idea is the same. Instead of storing the coordinates, you would store the key pressed instead.