This is a demonstration of how a computer keyboard works, in much smaller scale (2x2).

This is a very simple keyboard matrix. The code scans for logic voltage on pin 4 and 5. And depending on which pin is outputting between ping 2 and 3, it figures out which of the 4 button is pressed.