home

Keyboard matrix

How a Keyboard Matrix Works

Let's dive into how keyboard matrices work. It's a clever way to handle lots of keys without needing a ton of wires.

The Basics

Think about a regular keyboard - it has around 100 keys. Each key is just a switch that needs to tell the computer "hey, I'm pressed!" To do this, we need to connect each switch to the keyboard's brain (the microcontroller).
The naive way would be one wire per key. That's 100 wires! Not great. Instead, we use a matrix - it's like a grid of rows and columns that share connections.

Matrix Layout

Here's what it looks like in a real keyboard:
Col1 Col2 Col3 Col4 Col5 Row1 ESC F1 F2 F3 F4 Row2 ` 1 2 3 4 Row3 TAB Q W E R
Plain Text
복사
Each key sits at the crossing point of a row and column. When you press a key, it connects its row wire to its column wire.

The Diode Thing

Here's something cool - each key actually has a tiny component called a diode. It looks like this:
Row ----/-->|---- | | Col -----
Plain Text
복사
The /-->| is a switch with a diode. The diode only lets current flow one way, which is super important (more on that later).

How We Find Pressed Keys

The scanning process is pretty neat:
1.
Pick a row and send power through it
2.
Check which columns get power
3.
Any column that gets power = pressed key in that row
4.
Move to next row
5.
Do this super fast (like, thousands of times per second)

Why Diodes Matter

Without diodes, you get this weird issue called "ghosting". Here's what happens:
1.
Press three keys in a pattern like this:
Col1 Col2 Row1 X X Row2 X
Plain Text
복사
1.
Without diodes, current can flow backwards through the switches and make it look like you pressed the fourth key too! The diodes block this sneaky backflow.

Making It Better

Modern keyboards use a bunch of tricks to work well:
Diodes prevent ghosting
Fast scanning catches quick key presses
Debouncing ignores switch noise
N-key rollover lets you press lots of keys at once
The KEEBX firmware handles all this stuff automatically. It uses the matrix setup but adds smart features to make everything work smoothly.

Fun Fact

The matrix is why some old keyboards couldn't handle certain key combinations - they didn't have diodes, so they had to block some key combinations to prevent ghosting. That's where "3-key rollover" came from. Modern keyboards with diodes don't have this limit!

Comments