-The keyboard actually has some brains to it. No, its not a 400 megahertz CPU but a small microchip inside the keyboard. The microchip recognizes key presses and turn them into scan codes which are read by the keyboard controller on your motherboard.
-The keys of the keyboard themselves are all sitting above a sensor grid. The sensor grid detects a key depression thus alerting the microchip of a interrupt on the keyboard. After this is done the chip converts the depression into scan codes then its onto the controller on the motherboard. The controller actually checks the state of the keyboard by sending signals from the top and sides of the keyboard. This is done about a thousand times a second. The controller will be able to keep up with any event taking place on the board.