On my Apple keyboard (the white wired one, circa 2003, with an ergonomic curve to it) if I press both Shift keys down then it disables most of the QWERTY row. I guess this is some sort of ghosting or masking. Is it useful to be able to separately detect the two Shift keys? Why aren’t they wired on the same row/column intersection? That would eliminate this sort of masking. This makes me think far too hard about keyboard wiring designs and microcontroller pin minimisation. Observation: pin minimisation is the root of all keyboard misdesigns (well except for problems with the actual shape, action, and layout of the keys).
Electrically, keyboards are arranged in a matrix of rows and columns with a switch (corresponding to an actual key) at the intersection of each row/column pair. Depressing a key closes the switches and forms an electrical connexion between the row and the column. A microcontroller uses a scanning algorithm to detect key presses: it regularly scans the rows and columns by driving each row bus in turn and sensing each column bus to detect which keys are depressed. Warning: this description is made up by me based on my ancient knowledge of the ZX81 hardware design. I have no idea how modern keyboards work, but it’s probably something very similar. Probably you can get a single chip for USD 1 that does all this driving and sensing of the matrix, has a register and some LED drivers for the Caps Lock light, and a USB interface all in one. I suspect Apple have very little choice in how the electrical wiring of their keyboard is made.
The number of microcontroller pins I need for a keyboard of N keys is p+q where p×q ≥ N. If we assume that the cost of a microcontroller is proportional to the number of pins it has, then we would do well to minimise the number of pins we require for the keyboard matrix. For a 40 key keyboard (the ZX81) an arrangement of 8 rows and 5 columns is optimal. This comes about because we can only place one key at the intersection of each row and column. If we try and place two or more keys at the same intersection then the scan algorithm can’t differentiate between them.
However if we can somehow differentiate between two or more keys at the same intersection then we could put more keys per intersection and thereby reduce the number of pins we require.
Capacitance is Key
Suppose we put a capacitor inline with each switch. Now when a key is depressed instead of a closed circuit between a row and a column we get a resonant CR circuit. We can still use the scanning algorithm, but instead of driving the row bus with a constant voltage we drive it with a periodic signal. Obviously we should choose the period so that the CR circuit passes it. A 1.5 MHz square wave might be a good choice for a keyboard because we can get this from the clock used for the USB interface (12 MHz divided by 8). If we put different value capacitors on different key switches and drive the row with two different frequencies (1.5 MHz and 0.75 MHz say) then we can now detect two different keys at the same row/column intersection. We scan once at 1.5 MHz to detect one set of keys and scan again at 0.75 MHz to detect another set of keys.
For our ZX81 example with 40 keys we would need only 20 intersections which we can do with 4 rows and 5 columns, reducing our pin requirements from 13 to 9 pins. Awesome!
In general we save about 30% going from 1 key per intersection to 2 keys per intersection: we go from about 2×sqrt(N) pins to about 2×sqrt(N÷2) or sqrt(2)×sqrt(N). sqrt(2)÷2 is of course about 0.7.
More keys per intersection means greater savings, but also requires more frequencies, slower scanning (because each frequency requires an extra pass), and more stringent rejection requirements in the CR circuits.
For a really cheap and nasty keyboard, instead of having an open/closed switch inline with a capacitor simply make the keybaard so that two metal plates are brought close together when the key is depressed. The two metal plates form a capacitor whose value can be controlled by changing the area of the metal plates. (In fact, don’t really cheap and nasty keyboards use this principal already?) The challenge would be to reliably detect keys with different capacitance.