This is called a velocity-sensitive keyboard. This is implemented by having two switches per key, positioned so that one of them closes a bit later than the other during the travel of the key. You can see some pictures of such a system on [this page](http://www.openmusiclabs.com/learning/digital/input-matrix-scanning/keyboard/index.html).
When you hit the key harder, it moves faster, and the delay between the two switches closing is reduced. The CPU then uses that information about key travel speed to alter the sound being played.
Latest Answers