You press the letter A and, a few milliseconds later, it appears on the screen. Between those two facts lies a journey almost nobody imagines: the keyboard never actually knows which key you touched. It works it out. And it does so by interrogating a grid of metal traces dozens of times per second.
A hundred keys, twenty wires
A full-size keyboard has 104 switches. If each one needed its own wire to the microcontroller, and each wire also needed a connection to ground, we would be talking about more than two hundred solder joints. The invention that avoids that disaster is called a matrix: the switches are arranged in a grid of rows and columns, and each key sits at the crossing of one row and one column. With six rows and seventeen columns there are 102 crossings controlled by just 23 chip pins.
The microcontroller does not read keys: it reads intersections. It pulls one row low, holds the others high and reads the state of every column through pull-up resistors, which keep the line high until something pulls it to ground. If a column drops to zero, the switch at that crossing is closed. The firmware records the coordinate, moves to the next row and repeats.
A sweep every few milliseconds
The full cycle runs in a burst. Reading one row takes microseconds, so a complete sweep of the matrix stays well under a millisecond and the keyboard can repeat it hundreds of times per second while the processor does nothing else. An office keyboard usually scans at 125 Hz; gaming models advertise 1,000 Hz and a response time below one millisecond. The practical difference is small, but the mechanism is exactly the same.
The ghost of the third key
The matrix has a known flaw called ghosting. Picture three keys held down at three corners of a rectangle formed by two rows and two columns. Current can leave through the first row, cross the first key, climb its column, cross the second key, enter the second row and reach the fourth column through the wrong path. The controller sees voltage at a crossing nobody pressed: a phantom key, and along the way it stops telling some of the real ones apart.
The physical fix is a diode in series with every switch, usually a 1N4148 costing a few cents. The diode only lets current flow one way, from column to row, so the return path is cut and the ghost disappears. Mechanical keyboards that boast NKRO, meaning they register every key pressed at once, carry one diode per key. Membrane boards usually skip it: they use a flexible sheet with carbon traces and a rubber dome with a conductive pad, and the firmware simply blocks ambiguous combinations.
The bounce you have to ignore
When two metal contacts meet, they do not meet once. They bounce for one to five milliseconds and generate dozens of edges: the firmware could read one press as twenty. To avoid that it applies debouncing: it waits until the reading stays stable for a number of cycles before accepting the change. Some wait a fixed time, others use a per-key counter, faster on press and more conservative on release. It is a pure trade-off between latency and false triggers, which is why some keyboards let you tune it.
From keyboard to computer: eight bytes
The result of the sweep travels over USB using the HID protocol, which defines how keyboards, mice and gamepads describe themselves. The keyboard does not send characters: it sends key codes and modifiers. In the so-called boot report, the format understood by the BIOS and boot loaders, every packet is eight bytes: one for Shift, Ctrl, Alt and the Windows key, one reserved and six for the codes of the keys held down. If you keep a seventh pressed, the system never receives it and some machines beep.
To go beyond that limit, NKRO keyboards switch to their own report in which each key occupies one bit, up to 248 positions: a full bitmap of the keyboard. The price is that this format stops working in environments that only speak the boot protocol, such as certain old BIOSes.
The laptop case
In a laptop the matrix is not scanned by the CPU but by an embedded controller that stays powered even when the machine is suspended. That is why a keypress can wake it: the controller detects the closed circuit, raises an interrupt and starts the resume process. The same chip handles the Fn key, brightness or volume, which never reach the operating system as letters but as ACPI events.
Optical and Hall-effect switches
Optical switches replace the contact with an infrared beam that the stem interrupts as it travels down. With no metal rubbing there is no meaningful bounce, response time falls to tenths of a millisecond and lifespan is measured in a hundred million presses. Hall-effect switches go further: a magnet in the stem and a sensor that measures the magnetic field in analogue form, so the firmware knows the exact depth of the travel. That is where adjustable actuation and rapid trigger come from, reactivating the key as soon as it is released a fraction of a millimetre instead of waiting for it to come all the way back up.
Per-key RGB lighting adds a second matrix or a chain of shift registers, because every LED needs its own brightness level on top of the switch state.
The sum of latencies
Between your finger and the character there is a chain of waits: debouncing, which usually costs between two and five milliseconds; the sweep, which adds less than one; USB polling, one millisecond at 1,000 Hz; and the operating system plus the application, which can add several more. Pushing polling to 8,000 Hz shaves less than a millisecond off that chain and in exchange loads the CPU with more interrupts. Most of the delay you feel is not in the cable but in the software waiting its turn to draw the letter.
So every keypress is really an electrical deduction: a row pulled low, a column that drops, a diode that lets current through, a counter that settles and eight bytes crossing the bus. All so that the A appears where it was supposed to appear.






