Keys on a keyboard are laid out on a grid of wires (or rather, pcb traces) like below (simplified, the grid is not really ordered). When a key is pressed the horizontal and vertical vires are connected at that position. Pull high one and one horizontal wire at a time, and you can see what keys are pressed by checking which vertical wires also get pulled high, like so:
Code:
| | | | | | | | | | | | | | |
---X------- <-p ---X------- ---X-------
| | | | | | | | | | | | | | |
-------X--- -------X--- <-p -------X---
| | | | | | | | | | | | | | |
----------- ----------- ----------- <-p
| | | | | | | | | | | | | | |
V V
0 1 0 0 0 0 0 0 1 0 0 0 0 0 0
But when pressing three or more keys, problems can arise.
Code:
1 2 3 4 5
| | | | |
1---X---*--- <-p
| | | | |
2---X---X---
| | | | |
3-----------
| | | | |
V V
0 1 0 1 0
* "ghost key" appear a this position
h-wire 1 is pulled high. key at position 2,1 is held down so v-wire 2 gets pulled high. key 2,2 is also held down, so h-wire 2 also get pulled high. key 4,2 is also held down, so now v-wire also gets pulled high. But since it was wire h-wire 1 that got pulled high by the controller it looks like key 4,1 is pressed, when it's really not.
When ghost keys appear, you'll either get charaters on screen that you did not hit, or no more keys will register(and your PC might beep). When no more keys will register, it's because the keyboard controller recognises that ghost keys have appeared and ignoring new keys (not because the manefacturer has used diodes to prevent shorts, like I have seen some claim**)
Sorry about the confusing explenation.
**Such keyboards might exists, but then you would really be able to hold as many keys as you want a the same time without problems, it would not just prevent ghost keys but still limit your keypresses)