Skip to main content

How keyboards work: an interactive deep dive

ยท 2 min read
Martijn Smit

If you're reading this, you've probably pressed a key to get here. In fact, you press keys thousands of times a day. But what actually happens between your finger hitting plastic and a letter appearing on screen?

Turns out, quite a lot.

Every keystroke is a chain reaction that unfolds in about 5 to 25 milliseconds: a spring compresses, metal contacts bounce against each other (and need to be filtered), a matrix circuit scans for which key was pressed, a microcontroller translates that into a scan code, wraps it in a USB HID packet, and sends it across the cable to your computer โ€” where your operating system processes it and delivers it to the right application.

I've been wanting to understand this pipeline for a while. How does a matrix actually detect key presses? Why do some keyboards ghost? What's in those 8-byte USB packets? Where does latency come from, and what can you actually do about it?

So I went deep and built howkeyboardswork.com, an interactive guide that walks through the entire journey of a keystroke from switch to screen.

It's not a wall of text. Every concept has a hands-on demo:

  • Watch a keystroke travel through the complete pipeline, from physical switch to application
  • Click keys in a virtual matrix to see row-by-row scanning, and toggle diodes off to trigger ghosting
  • See contact bounce in a waveform and compare debouncing strategies
  • Build a live USB HID report byte by byte, and hit the 6-key rollover wall
  • Explore scan codes across keyboard layouts: same physical key, same code, different character
  • Tweak latency parameters and watch milliseconds add up across the stack

Whether you're into mechanical keyboards, curious about low-level hardware, or just like understanding the tools you use every day, I hope this scratches that itch.

Check it out: howkeyboardswork.com