1.
The Matrix: How Keyboards "See" Your Input
At the most basic level, a keyboard is a grid of open switches. If the processor had a dedicated
wire for every single key (roughly 104 on a standard board), the wiring would be a nightmare.
Instead, keyboards use a Key Matrix.
● The Grid: Keys are arranged in rows and columns.
● The Scan: The keyboard controller sends a sequential electrical pulse down each
column.
● The Detection: If a key is pressed, it completes the circuit for a specific row. By knowing
which column was pulsed and which row returned a signal, the controller identifies the
exact coordinate of the key.
Key Concept: Ghosting
"Ghosting" occurs when you press three or more keys simultaneously, and the
matrix logic gets confused, reporting a keypress that didn't happen. High-end
keyboards use Diodes on every switch to prevent backflow, allowing for "N-Key
Rollover" (NKRO).
2. Switch Technologies: Mechanical vs. Membrane
The way a key physically registers a "hit" determines the tactile feel and durability of the device.
Membrane (The Standard)
Most modern keyboards use a three-layer plastic membrane. When you press a key, a rubber
dome collapses, pushing a conductive trace on the top layer to meet a trace on the bottom
layer.
● Pros: Cheap, spill-resistant, quiet.
● Cons: "Mushy" feel, shorter lifespan (approx. 5–10 million keystrokes).
Mechanical (The Enthusiast Choice)
Each key has its own dedicated physical switch housing with a metal spring and gold-plated
contacts.
● Linear: Smooth travel (e.g., Cherry MX Red).
● Tactile: A "bump" you can feel (e.g., Cherry MX Brown).
● Clicky: A bump plus an audible "click" (e.g., Cherry MX Blue).
3. The Communication Protocol
Once the controller identifies a keypress, it doesn't send the letter "A" to the computer. It sends
a Scan Code.
Scan Codes vs. ASCII
The keyboard sends a unique hex code for the physical location of the key.
1. Make Code: Sent when the key is pressed.
2. Break Code: Sent when the key is released.
The Operating System (OS) receives these codes and uses a Keyboard Layout Map (like
QWERTY or Dvorak) to translate them into characters (ASCII or Unicode). This is why you can
change your keyboard language in software without changing the physical hardware.
Interrupt-Driven I/O
Keyboards usually operate via Interrupts. Instead of the CPU constantly asking, "Did you press
a key?" (polling), the keyboard controller sends a signal to the Interrupt Controller. The CPU
pauses its current task, handles the keystroke, and then resumes.
4. Debouncing: The Hidden Logic
In the physical world, when metal contacts meet, they don't just "touch"—they vibrate and
"bounce" for a few milliseconds. To a high-speed processor, a single tap might look like 10 rapid
presses.
Debouncing is the process (either via hardware capacitors or software algorithms) of ignoring
any additional signals for a few milliseconds after the initial contact to ensure only one character
is registered.
5. Ergonomics and Alternative Layouts
The QWERTY layout wasn't designed for speed; it was designed to prevent mechanical
typewriter arms from jamming by separating common letter pairs.
● Dvorak: Places the most common letters on the "home row" to minimize finger travel.
● Colemak: A middle ground between QWERTY and Dvorak.
● Ergonomic Splits: Designed to keep wrists at a natural angle (ulnar deviation) to
prevent Repetitive Strain Injury (RSI).
Summary Table
Feature Membrane Mechanical
Actuation Pressure on rubber dome Metal contact points
Feedback Soft/Mushy Tactile/Audible
Lifespan ~5-10 Million clicks ~50-100 Million clicks
Rollover Usually 2-6 keys Full N-Key Rollover
Would you like to dive deeper into the assembly-level interrupts (how the CPU handles the
IRQ) or perhaps the capacitive sensing used in high-end Topre switches?