Saturday, February 18, 2006
“Now THAT'S a keyboard!”
Dan Lyke linked to several manual typewriters used as computer keyboards (the ElectriClerk perhaps being the coolest of the three, going all Brazil with an old Macintosh SE). As I'm reading about the typewriter-keyboard conversion, I was struck that the person doing it might now know how keyboards work:
Like I said earlier, each key is a connection between two terminals. Some terminals have lots of keys connected to them. For example, connecting terminal 4 and terminal 19 might produce “A” but connecting terminal 9 and terminal 19 might produce “F”. Since 1-13 always connected to 14-26 and vice versa (i.e. no terminal from 1 to 13 connects to any other terminal from 1 to 13), I arbitrarily decided that the levers would all connect to 1 13 and the crossbar would connect to 14-26.
A keyboard is basically a matrix of switches. Here's the schematic of the keyboard used on the Color Computer 2 (a very simple 53-key keyboard):
(“EN” is the Enter
key, “CL” is the Clear
key,
“BR” is the Break
key, “SP” is the Spacebar
and
“SH” are the Shift
keys)
You would write a “0” to each column (so, to read the rightmost column,
you would write a value of 254 (in binary—11111110
) and then
read the rows. In each case where there is a 0 there is a key being held down
along that row. So, again, for the right most column, if you read in 187 (or
10111011
in binary) the Shift
key (either one,
since they're wired together) and the “W” key are being pressed.
There's a bit more to it than that—the code to read the keyboard would
scan through each column, and it would have to know to flag the
Shift
key as being up or down, and once it detected a key (or
two) being down, it would have to pause for a bit, then re-scan for that key
(which is called “debouncing”—as you press the key the electrical contact may
switch on and off as the key is being hit)—but that's basically how all
computer keyboards work (more or less—your standard PC keyboard these days
are very simple computers themselves that scan the keyboard matrix and send a
standardized code for each key to your computer).