Skip to content
0:00 / 0:00

#usb#usbprotocol#keyboard

How does a USB keyboard work?

Ben Eater

1.4M subscribers • 28 videos on Hallway

YouTube
  • Recommended by 8 people: 7 on Hacker News and 1 on Lobsters.
  • A classic. People kept recommending it from 2021 to 2024.
  • Presented by Ben Eater

Intermediate. Assumes working knowledge.

3.7M views5 years ago8 recommendations

HardwareSystems programmingEmbedded systemsNetworking and protocols

Ben Eater explains the USB protocol by analyzing how a USB keyboard communicates, covering electrical signaling, packet encoding, and PS/2 differences.

The USB 2.0 spec: eater.net/downloads/usb_20.pdf Support these videos on Patreon: patreon.com/beneater or eater.net/support for other ways to support. Intro USB electrical interface How USB encodes bits and packets USB packet contents USB vs. PS/2 ------------------ Social media: Website: eater.net Twitter: x.com/beneater Patreon: patreon.com/beneater Reddit: reddit.com/r/beneater Special thanks to these supporters for making this video possible: Aaron Todd, Aleksey Smolenchuk, Alexander Wendland, Andrew C. Young, Anson VanDoren, Anthanasius, anula, Armin Brauns, Ben Cochran, Ben Kamens, Ben Williams, Benny Olsson, Bill Cooksey, Binh Tran, Bouke Groenescheij, Bradley Pirtle, Bradley Stach, Brent Reusing, Bryan Brickman, Carlos Ambrozak, Christian Carter, Christopher Blackmon, Dale Andrew Darling, Daniel Jeppsson, Daniel Tang, dans, Dave Burley, Dave Walter, David Brown, David Clark, David Cox, David House, David Sastre Medina, David Turner, David Worsham, Dean Bevan, Dean Winger, Dissy, dko, Dmitry Guyvoronsky, Dušan Dželebdžić, Dustin Yelland, Dzevad Trumic, Eric Dynowski, Erik Broeders, Eugene Bulkin, George Miroshnykov, Harry McDow, hotwire33, Ian Tait, Ingo Eble, Ivan Sorokin, James Capuder, james schaefer, Jared Dziedzic, Jason DeStefano, Jason Specland, JavaXP, Jaxon Ketterman, Jay Binks, Jayne Gabriele, Jesse Miller, Jim Kelly, Jim Knowler, Jim Van Meggelen, Joe Beda, Joe OConnor, Joe Pregracke, Joel Miller, John Fenwick, John Meade, Jon Dugan, Joseph Portaro, Joshua King, Jurģis Brigmanis, Kai Wells, Kefen, Kenneth Christensen, Kent Collins, Kitick, Koreo, Lambda GPU Workstations, Larry, László Bácsi, Lucky Resistor, Lukasz Pacholik, Marcos Fujisawa, Marcus Classon, Mark Day, Martin Roth, Mats Fredriksson, Matt Krueger, Matthäus Pawelczyk, Matthew Duphily, melvin2001, Michael Tedder, Michael Timbrook, Michael Weitman, Miguel Ríos, mikebad, Mikel Lindsaar, Miles Macchiaroli, Muqeet Mujahid, My Yiddishe Mama, Nicholas Counts, Nicholas Moresco, Nick, Not Yet Wise, Paul Pluzhnikov, Paul Randal, Pete Dietl, Phil Dennis, Philip Hofstetter, Phillip Glau, PixelSergey, ProgrammerDor, Randal Masutani, Randy True, raoulvp, Renaldas Zioma, Ric King, Rick Hennigan, Rob Bruno, Robert Comyn, Robert Diaz, Roland Bobek, sam raza, Scott Holmes, Sergey Kruk, Shelton, SonOfSofaman, Stefan Nesinger, Stefanus Du Toit, Stephen, Stephen Riley, Stephen Smithstone, Steve Jones, Steven Zilberberg, Tayler Porter, TheWebMachine, Thomas Bruggink, Thomas Eriksen, Tii, Tom, Tom Yedwab, Tommaso Palmieri, Tyler Latham, Vincent Bernat, Vladimir Solomatin, Walter Montalvo, Warren Miller, Wim Coekaerts, Wraithan McCarroll, xisente, Yee Lam Wan

Why it's here

8 people recommend this

What people say. Highly recommended as an exceptionally clear and detailed explanation of the low-level USB protocol and keyboard communication.

Hail_Spacecakeon Lobsters • Recommends

How does a USB keyboard work?

jordibcon Hacker News • Recommends

On “The end of the nice GTK button”

About the USB keyboard, that may be true only for the cheapest keyboard you could find, but basically not applicable anymore nowadays. Rather than giving you the details, let me link to this video, which is awesome at explaining it and much more -- the USB vs PS/2 part starts here: link to this video

ericbarretton Hacker News • Recommends

On “Only buy a magnetic keyboard for gaming”

Among other things, the USB host polls the keyboard at a fixed rate. Fantastic breakdown if you have 30 minutes: link to this video

wmwmwmon Hacker News • Recommends

On “Keyboard Latency (2017)”

There’s a great video here that goes through all this - the gist is that USB keyboards specify what polling rate to use, 1000hz for the best ones, maybe 125hz for the cheaper ones. An interesting thing about ps/2 is that even though it doesn’t have to wait for the keyboard to poll it transmits data at much slower speed than USB (khz vs mhz) which somewhat offsets the advantage it gets from being interrupt driven link to this video edit: ah, sorry, I see someone's posted a link to this video already!

exporectomyon Hacker News • Recommends

On “Keyboard Latency (2017)”

Apparently 1 PS/2 limited by a slower data rate than USB 2.0 which cancels out almost all the advantage of its lower initial latency to begin the transmission, making them both about equally capable in actual latency - at least in theory. 1 link to this video Even if this conclusion is wrong, that video is a very pleasant and understandable explanation of the USB protocol.

throw0101aon Hacker News • Recommends

On “What is AT&T doing at 1111340002?”

> Embedded programming? Dealing with signals?! God forbid, man. "How does a USB keyboard work? by Ben Eater: * link to this video

jai_on Hacker News • Recommends

On “How to Make Rust Leak Memory (Also: How to Make It Stop)”

If you're interested, here's a really comprehensive video on how USB keyboards work which may answer your question: link to this video

lozengeon Hacker News • Recommends

On “Ask HN: How do I write a Linux driver for my 15 year old photo printer?”

Ben Eater has some videos showing the USB protocol on an oscilloscope. link to this video link And some videos on using chips and breadboards to meet protocols- link And a digital protocol too- link

u/StochasticTinkrin r/compsci • Mentions

On “Does everything in computer run on an event loop?”

I recently learned that is no longer true with USB. Usb peripherals are polled by the host, there is no interrupt mechanism and the protocol dictates that the host addresses them first. Ben Eater did a video on it link to this video

u/Ragingman2in r/compsci • Mentions

On “Question about ones and zeroes”

Computers use ones and zeros in a million different ways, and each protocol we use has a unique answer to this question. Inside a CPU data is usually passed around in blocks of 32 or 64 bits, using one "cable" per bit. USB, HDMI, PCI-E, UART ... all have unique ways of handling this problem. Here is a good deep dive into how USB solves the problem link to this video .

thristianon Hacker News • Mentions

On “How does USB device discovery work? [video]”

Piggy-backing this comment to add some context for the OP video: This "USB device discovery" video is actually the latest in a series of videos where Ben Eater is building a simple 8-bit computer on breadboards. He hooked up a PS/2 keyboard as an input device, and then got sucked into a tangent of investigating and explaining keyboard protocols. - He investigates the PS/2 keyboard protocol: link - Somebody on Patreon asked about USB keyboards having higher latency than PS/2, so he made a video about the basic USB protocol: link to this video - He made the OP video about USB keyboards being limited to holding six keys at once.

RJIb8RBYxzAMX9uon Hacker News • Mentions

On “IBM PS/2 Keyboard Modification”

I'd imagine it would be very difficult, and would require a relatively powerful MCU. Ben Eater's made a few videos discussing how PS/20 and USB keyboards1 work. USB's a vastly more complicated protocol compared to PS/2. 0 link 1 link to this video

em3rgent0rdron Hacker News • Mentions

On “A blue connector does not USB 3.0 make”

I'm sorry but serious question, why would you need a high-speed for a keyboard? A usb packet for a keystroke is roughly 180 bits (I'm estimating from glancing at link to this video ). So 1.5 Mbit/s low speed could roughtly handle over 8,000 keystrokes per second. Do you really need more keystrokes or finer resolution than that?

lasr_velocirptron Hacker News • Mentions

On “Measured typing latency of popular terminal emulators”

PS/2 Keyboards are faster than a USB keyboard with slow-speed negotiation with the host computer but for USB keyboards with high speed negotiation, they are at par1 1 link to this video

jeroenhdon Hacker News • Mentions

On “Writing a basic Linux device driver when you know nothing about Linux drivers”

…derpowered ones designed for industrial applications and such). Even the most GAMING of motherboards have headers ready for one or even more serial ports to mess with. All you need is a cable and a card to slot into a PCIe bracket! USB itself, at least the 1.1 protocol that's still used for some devices today, isn't all that complicated in itself: link to this video Many if the complicated parts here, like device identifiers, are the things you'd need to manually configure if you were to use a serial port. Those hundreds of pages are similar to the hundreds of device types, vendors, and models that Windows would list when you clicked "add new hardware" back in Windows 98. When push comes to shove, you'…