Mike said:
Since nobody has covered this part:
Keyboards send signals to the computer each time you press or release
a key. These signals include a number indicating the position of the
key on the keyboard (NOT the character printed on the key), and a flag
to indicate whether the key has been depressed or released. The
operating system running on the computer collects these numbers
(called scan codes) as they arrive from the keyboard, and uses tables
and some other logic to translate the scan codes into actual
characters.
Keyboard repeat, which is handled by the keyboard, sends multiple "key
depressed" signals if you hold a key down for more than a certain
amount of time. This is called typematic behavior.
N-key rollover refers to the ability of a keyboard to send a signal to
the computer for a second, third, or nth key when it is depressed even
before preceding keys are released. Four-key rollover means that you
can do this with up to four keys; once four keys are simultaneously
depressed, pressing additional keys without releasing a key has no
effect. Sometimes rollover applies only to alphabetic or certain
other keys. N-key rollover is common today, but not universal, and
may not apply to all keys.
Some keys are handled in a special way. Instead of the keyboard
generating a single scan code for the key, it generates codes for some
other key (usually a shift key), followed by the actual key changing
state, followed potentially by another code for another (shift) key.
This allows a bit more flexibility in the way the keyboard behaves,
but it also requires more complex keyboard drivers, and it requires
that the keyboard keep the shift states (capitals, numeric lock,
function keys on some keyboards, etc.) memorized locally.
Many keyboards have indicators for shift lock and other states. These
can be controlled by the computer and may or may not correspond to the
keyboard's own internal state memory (if any). Additionally, the
keyboard driver may or may not respect these state indicators (they
can get out of sync, or the OS may simply not care about them).
Keys are assigned scan codes roughly from left to right and from top
to bottom. Scan code 00 is not used.
The keyboard sends data serially to the keyboard controller in the
computer. Two-way communication is possible on recent keyboards
(setting shift status and so on). A BIOS interface simplifies reading
scan codes and/or characters from the keyboard.