How do I record button presses and play them back?

PaulS -

"By recording the previous state, in an array"

Can you teach me how to do this?

I actually have some switches with keyboard-style tops on them so how would you define them?