Not having done anything like this, I'm just looking at it logically.
To 'record' it, I assume you don't really want to record the sound, but the presses.
To be able to record you will need a start/stop too. (If you use the first press as start, you will still need a 'stop' or how will you know it's over)
Once you start, I can only think that you will need to have a timer, and as each button is pressed, record that press and how long the press is down for.
Eg: — seconds, button 4 was pressed for 1.4902 seconds.
Then, you can 'auto' play back based on these button presses, as well as you could then save/load the 'tunes' and add/change them.
Food for thought.