Comments by "LoneTech" (@0LoneTech) on "What Happens When I Press a Key? - Computerphile" video.
-
7
-
USB is most certainly not using set 2 - for the reason why, look up what the scancode is for the arrow keys, which have a prefix for set 1 compatibility, or the Pause key which is 7 bytes long. USB keycodes are in alphabetic order and Z in particular is 1D (see HID usage tables, section 10 keyboard). Your firmware might be translating it for legacy OS support, however. Set 3 was more logical in that it used a single bit for press/release and one byte for each event. Also, the polling in USB is performed by the host controller, not the CPU, so we still have an interrupt for when things have changed. There are also buffers in both keyboards and port controllers for PS/2, AT etc, but the CPU typically has to handle them byte by byte.
7
-
6
-
3
-
2
-
1
-
Yep, this tradeoff between polling and interrupts does exist! Interrupts cause a context switch, which involves saving some state and jumping to another routine, possibly waking up a CPU that was sleeping entirely. Spinning the CPU on a single task can achieve faster reaction times on many, but not all, processors (the exceptions tend to have hardware contexts, like SPARC register windows, ARM fast interrupts or XMOS threads). The point I was making is that the CPU receives the interrupt when the message has arrived; it is not involved while the keyboard is transferring, and does not need a round trip to interrogate the keyboard. It's more like the mail man leaves the note at the desk you're already working than you answering the bell. (On PS/2, there's a high risk the CPU is fast enough to switch back and forth for each byte, which can get costly as many messages are several bytes long.)
1