HN Theater @HNTheaterMonth

The best talks and videos of Hacker News.

Hacker News Comments on
How does a USB keyboard work?

Ben Eater · Youtube · 206 HN points · 11 HN comments
HN Theater has aggregated all Hacker News stories and comments that mention Ben Eater's video "How does a USB keyboard work?".
Youtube Summary
The USB 2.0 spec:

Support these videos on Patreon: or for other ways to support.

0:00 Intro
0:50 USB electrical interface
4:43 How USB encodes bits and packets
23:41 USB packet contents
29:26 USB vs. PS/2


Social media:

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
HN Theater Rankings

Hacker News Stories and Comments

All the comments and stories posted to Hacker News that reference this video.
Ben Eater has some videos showing the USB protocol on an oscilloscope.

And some videos on using chips and breadboards to meet protocols-

And a digital protocol too-

With existing USB devices you don't usually need to go nearly this low level to reverse engineer them - just enumerating the endpoints and then using Wireshark and USB packet capture is plenty sufficient.

Understanding how the USB wire protocol works is definitely valuable knowledge in some arenas, but not at all important for the kind of reverse engineering task OP is trying to perform, as they can generally speaking trust the electrical layer is standard and only need to operate at a level above it.

Same for the "write 3 bytes to a USB device" hypothetical from upthread - electrical understanding of USB is interesting but ultimately unimportant if you're using an existing USB stack - higher level knowledge of USB endpoint types and transport mechanisms is the name of the game there.

If I were given this task and I had to produce a driver with source code (rather than just get things working), I'd start with a combination of USB sniffing and static decompilation (Ghidra/IDA) of the Canon binaries, followed by perhaps some dynamic analysis (logging shims) if things turned out very complex.

If I just had to get things working, I'd just use one of the many approaches to mix 32/64-bit userland binaries in order to shim the 32 bit Canon binaries into a 64-bit CUPS driver.

Jul 02, 2022 · 170 points, 25 comments · submitted by marbu
Is there anything like this on how optical mice work? It'd be interesting to see how the sensor and algorithm works.
A USB mouse just sends x/y distance traveled over USB HID protocol. All the details are integrated into silicon. The sensor is a camera and the processor diffs the images to calculate the distance. To learn about the algorithms for that you could look into patents by Avago or PixArt.
Look into HP patents around 1990-99 on optical paper sensors. Afaik mouse sensor came from research into large format plotter paper tracking.

US Patent 5,729,008. Interview with inventor: Oral History of Travis Blalock

"each array element had nearest neighbor connectivity so you would calculate nine correlations, an autocorrelation and eight cross-correlations, with each of your eight nearest neighbors, the diagonals and the perpendicular, and then you could interpolate in correlation space where the best fit was. "

all in analog domain

another one from HP/Agilent/Avago: Oral History of Gary Gordon

also this

Ben Eater makes amazing educational videos, unfortunately he's been MIA for half a year now. His patreon sneakily got updated from a "per video" to a "per month" payment model a couple months ago (this has since been reverted) and I cancelled my membership after I didn't get any explanation for over a week, and there have been no other signs of life as far as I know.
I'd give Ben the benefit of the doubt and assume it was a mistake since up to that point he has been a class act.

As for the radio silence, I'm afraid that this could be something bad. I've seen other examples of creators doing great work who are seemingly impossible to dislike, and STILL receive harassment to a point of not wanting to continue (e.g. Handmade Hero)

> I've seen other examples of creators doing great work who are seemingly impossible to dislike, and STILL receive harassment to a point of not wanting to continue (e.g. Handmade Hero)

Are you saying that Casey Muratori is "seemingly impossible to dislike"? Isn't he still doing HH?

What kind of harassment did Casey receive? Was it if the “this is stupid because he’s not using an engine variety”?
He didn't go into details of harassment when speaking about it, which is understandable, except that it was about things he said on stream.
Well, nevermind anything nefarious, life can throw unexpected things in the mix too. This Old Tony was similarly away for a while recently (now back) after a family member died. I imagine it only gets more difficult to return too, once people notice and maybe you see them asking in comments, on Reddit or HN, etc. 'where' you've gone, and start to feel some need to not only return but explain your absence.

I check occasionally for new videos, I enjoy them and hope there's more to come, but I don't need to know 'why', it's none of my business, and he doesn't owe me anything. (I'm not a Patreon supporter, that apparent change is a bit different of course, perhaps just a mistake as you said.)

All I want is a simple "channel on hiatus for personal reasons" post somewhere.
Def. agree on this one.

I'm reminded of the closure viewers of the YouTuber Bosnian Bill got about his disappearance, by Lock Picking Lawyer doing an explanation video:

But I do also understand not all creators have a relationship with another creator which as much overlap of audience that it is possible.

I'm very surprised Patreon would let a creator switch that without asking for existing patron's consent, it seems ripe for abuse and borderline illegal.
They hope their creators will inform them it seems, although maybe there is a patreon-initiated email informing backers when they make this change (I just can't find any evidence of it).

> Letting your patrons know about billing changes in advance is most important when switching from per creation to another option. Patrons may want to upgrade their subscription if they know that their pledged amount will be x 1. Say Patron F is at your $5 tier with a monthly max of 2 creations per month. When you switch to monthly, their subscription amount defaults to $5 a month -- they may want to increase to $10 a month to account for the change.

IANAL, but this still looks very suspicious to me. Agreeing to pay someone $5/month is not the same as agreeing to pay them $5/video (or vice versa). Charging me for something I never authorized is a form of fraud, no?
I'm sure the ability to do so is buried in 50 pages of terms of service.
Terms of Service don't override the law or CC networks' rules.
If their class action waiver holds, that's fairly irrelevant.
He was around for sure in Feb, I was emailing him and he replied.
Yeah, I'd wondered what he's up to. At the same time, people have their own lives and sometimes shit happens. Changing the terms for existing patrons though does sound slightly shady. I'm surprised that is allowed without some kind of confirmation on the platform.
I believe Patreon sends backers an email, however it doesn't require a confirmation from every patron to continue supporting.
Are there any tools on mac that shows how much bandwidth is being used on a usb/thunderbolt port? I've always suspected that I'm saturating the connection from laptop to hub but don't have a definitive way of knowing for sure. When I move my second monitor off the hub and plug directly into a different usb port on my laptop I seem to have less problems.
CL!ng may be what you're looking for [1]. The app is available in the App Store, but I have not tested it.


You can use a cable like this

Note I am not recommending this specific cable; it is just the first one that showed up in my search.

That cable only shows power draw not bandwidth. And I'm not aware of a cable that does show bandwidth.
Wireshark has usb tools, might be derivable.
If you're interested, here's a really comprehensive video on how USB keyboards work which may answer your question:
Wow, that was an absolutely incredible breakdown. Didn't expect to watch a 30min video on the USB protocol tonight.

Really didn't expect to suddenly want an oscilloscope.

Ben Eater has one of the best channels on YouTube! If you haven’t already, check out his 8 bit bread board computer series. He explains how to make a computer, completely from scratch. Coming from the software world, I found this to be absolutely fascinating!
Any idea why Ben hasn't posted in a while?
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 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?
"I have a couple devices that might be nice if they had keyboards but don't support USB1 low/full speed. "

Its not about the keyboard, its about the host not supporting USB1 speeds or TTs.

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:
Nov 11, 2021 · 2 points, 0 comments · submitted by ivanmaeder
> Embedded programming? Dealing with signals?! God forbid, man.

"How does a USB keyboard work? by Ben Eater:


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/2[0] and USB keyboards[1] work. USB's a vastly more complicated protocol compared to PS/2.



You only need a bare minimum host controller (USB 1.1) to accept a keyboard, and hardcode everything in the firmware to assume one. A suitable MCU is pretty cheap:

Looks like someone already made (at least the source) for an adapter based around that MCU family available:

As for relative lack of availability, I think that says more about how many people want to use an old keyboard with a new computer (semi-common) vs. a new keyboard with an old computer (rare).

From your link:

> The CH554 is a microcontroller with an E8051 core with a 24 MHz clock, a little more than 1 kB of RAM, and a bit more than 14 kB split between the code and data Flash.

I think that qualifies as "relatively powerful" when compared to a Z80 or 6502. :-)

I do agree that the lack of such adapters is due to zero market demand though.

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.


Even if this conclusion is wrong, that video is a very pleasant and understandable explanation of the USB protocol.

I wonder how much CPU load changes the equation. I've experienced USB input locking up or stuttering as a result of high CPU load, which presumably wouldn't happen with PS/2.
Sep 03, 2021 · wmwmwm 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

edit: ah, sorry, I see someone's posted a link to this video already!

Sep 03, 2021 · bschwindHN on Keyboard Latency (2017)
> Also wondering how much PS/2 vs USB matters.

Ben Eater has a great video on this:

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:

- Somebody on Patreon asked about USB keyboards having higher latency than PS/2, so he made a video about the basic USB protocol:

- He made the OP video about USB keyboards being limited to holding six keys at once.

> on breadboards.

Whatever happened to wire wrap?


I can understand BBs for quick prototyping and tinkering, but once you've settled on the design, I'd think WW would be less fragile to deal with.

Jun 10, 2021 · 1 points, 0 comments · submitted by diplodocusaur
Jun 09, 2021 · 2 points, 0 comments · submitted by tambourine_man
Jun 07, 2021 · 3 points, 0 comments · submitted by signa11
Jun 06, 2021 · 9 points, 0 comments · submitted by ahaferburg
Jun 06, 2021 · 6 points, 0 comments · submitted by tambourine_man
Jun 05, 2021 · 13 points, 0 comments · submitted by marbu
HN Theater is an independent project and is not operated by Y Combinator or any of the video hosting platforms linked to on this site.
~ yaj@
;laksdfhjdhksalkfj more things ~ Privacy Policy ~
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.