Record/keylistener?

Hey all. I have a question that I really hope to get a few pointers on, or at least a shove in the right direction. Thanks.

Can keylisteners be used to record keystrokes for later playback? If not, what can? The goal is to develop a way for individuals to make their own music via keypresses.

For example: The R key is pressed to start the recording of the user’s keyboard, with each keystroke assigned to play a different movieclip/audio, etc. The S key is then pressed to stop the recording. Lastly, the P key is pressed to play those movieclips/audio,etc. in their recorded sequence at the enjoyment of the individiual user.

Keystroke = piano key/note
R = Record
S = Stop
P = Play (the newly created piano music)

How can this be done?