How Computers Work Beginner

How Does a Keyboard Know Which Key You Pressed?

It's not magic! Pressing a key connects one row and one column in a hidden grid. The keyboard scans the grid, finds that position, matches it to a keycode, and sends the code โ€” not the letter โ€” to the computer, which decides what character it means.

๐Ÿงช This lesson has a hands-on activity ↓

Download the poster

You press the A key and an "a" shows up on the screen. But the key doesn't send a tiny letter down the cable โ€” it sends a code. Here's how the keyboard figures out which key you pressed.

You press a key. The first question is simple: how does the computer even know which key moved? It can't see your fingers. The answer is hidden underneath.

The key closes a switch. Under each keycap (the part you press) is a tiny switch. Pressing the key closes the switch, which completes an electrical path โ€” like flipping on a light.

A row-and-column grid. Running a separate wire to every key would need far too many wires. So most keyboards wire their switches in a grid of rows and columns. Each key sits where one row and one column cross. Press A, and its switch connects Row 3 and Column 2.

The keyboard scans the grid. Many times each second, a tiny controller checks the grid column by column, looking for closed switches. When it checks Column 2 and Row 3 responds, it knows exactly which key you're holding down.

The position becomes a keycode. The keyboard's firmware matches that grid position (Row 3 + Column 2) to a keycode. It sends that code to the computer โ€” not a little letter A traveling through the cable, just a number that means "this key."

The computer interprets the code. Now the operating system turns the keycode into a character. It checks Shift, your language, and your keyboard layout. The same keycode can become "a" on its own, "A" with Shift held, or a different letter on another layout like French.

The app displays the result. The keyboard also reports press, hold, and release, and the app decides what to do with each. Press it, find the position, send the code, interpret it โ€” that's the whole journey from your finger to the screen. Be curious, not careless!

๐Ÿงช Try it yourself

What to remember

  • Under each key is a tiny switch that closes an electrical path when you press it.
  • Keys are wired in a grid of rows and columns, so pressing one connects one row and one column.
  • The keyboard sends a keycode for that position โ€” not a tiny letter traveling down the cable.
  • The computer turns the keycode into a character using Shift, language, and layout settings.

Words to know

Switch
A tiny part under each key that closes an electrical path when pressed.
Row-and-column grid
A hidden grid of wires so each key sits where one row and one column meet.
Scanning
The controller checking the grid many times a second to find closed switches.
Keycode
A number that stands for a key's position, sent to the computer.
Keyboard layout
The setting that decides which character each key makes (like English or French).

For grown-ups

A keyboard doesn't run a separate wire to every key โ€” that would need dozens of wires. Instead the switches are wired in a matrix of rows and columns. A microcontroller inside the keyboard scans the matrix, energizing one column at a time and checking which rows respond, many times per second. When a key is down, its switch connects a specific row and column, so the controller can pinpoint the location. Firmware maps that (row, column) position to a scancode/keycode and sends it over USB or Bluetooth. Only then does the operating system interpret the code into a character, applying modifier keys (Shift, Ctrl), the active keyboard layout, and the language โ€” which is why the same physical key can produce 'a', 'A', or a different letter entirely on another layout. (Matrix scanning is also why cheap keyboards can 'ghost' when several keys are pressed at once, and why gaming keyboards add anti-ghosting circuitry.) The kid-sized idea: press it, find the position, send the code, interpret it.

Want the full story? These go deeper: