The keyboard works in the same way as the mouse. You move your finger over the keys, and the keys respond to the motion.
If you want to know how the keyboard works, you can look at this video. It shows a keyboard being pressed down and then being released. It shows how the key switches are activated and how the keys respond to the motion.