Ahh, the keyboard. Platter of choices. Pallet of Arabic characters. Based on the QWERTY layout introduced in 1867, the keyboard is our portal to the world. But just how do they work?
First, it is important to note that this article centers on modern, computer keyboards. Check back later for the physics of a typewriter. Modern computer keyboards feature upwards of 70 keys (I just counted, mine has 84) which take a consistent and relatively small magnitude of force to depress and register as a keystroke. On my keyboard, this consistent force is provided by a small synthetic spring and series of two levers.
The spring is formed through a molded piece of what appears to be silicone, with small "humps" where each of the keys are located. These humps compress in a manner where the first millimeter or two of displacement requires most of the total force, and the rest of the displacement requires very little force. Practically, this means that the keys can support quite a bit of force (say, the weight of one's fingers), while still being relatively easy to compress.
I believe that the two small sliding levers function only to keep the keys oriented correctly, as they are sprung but very, very lightly.
If one had far, far too much time on one's hands and wanted to the spring constant of a key over its displacement, one could set up a range finding system to measure the acceleration of the key when a constant force is applied. This graph could then be examined to determine the change of net force and, therefore, variation in spring constant across the displacement. Let's not do that though, because that's the sort of thing only done by thirty year old guys named Ted who live in their mothers' basements.