1) As a key goes down, the hammer travels towards the string (or strings: most notes on a piano have 2 or 3 strings).
2) At the same time as the hammer is moving, the damper (the block of felt that stops the strings from vibrating) is released so that the strings can sound.
3) When the hammer hits the strings, it has to bounce off very quickly. This is very important. If the hammer stayed on the strings instead of bouncing off, you would just get a dull thud instead of a proper musical note.
4) When the key is released, the damper goes back into position to stop the note from sounding. (That is unless the damper pedal – the one on the right – has been pressed, in which case the dampers on all the strings of the piano will be off).
The whole process (for an upright piano) can be seen in the video below. From 0:09 you can see the hammer bouncing off as a longer note is played. Use the video settings to select a slower playback speed if you would like to see it in more detail.