How does the keyboard autorepeat setting work?


Commenter eric johnson wonders how that control panel keyboard autorepeat setting works.

This is one of those questions that has many answers, depending on how deep you want to dig.

The first layer of the question is how the control panel changes the keyboard autorepeat rate. That's simple: It uses SystemParametersInfo(SPI_SETKEYBOARDSPEED). From the documentation, you can see that the keyboard speed is an integer in the range 0..31, where 0 indicates 2 characters per second and 31 indicates approximately 30 characters per second.

The next layer of the question is why the SystemParametersInfo expresses the keyboard autorepeat setting in a 0..31 range, and why the upper end of the range is 30 characters per second. Well, the SystemParametersInfo function is merely passing the buck; that is the format that the Windows keyboard driver uses.

Okay, so why does the Windows keyboard driver use this representation for the keyboard speed? Because that's how the hardware keyboard autorepeat setting works. Command 0xF3 sets the keyboard autorepeat, and it takes a single byte argument, of which the bottom five bits encode the autorepeat speed, ranging from 2 characters per second up to 30. (That document describes the PS/2 keyboard interface, but the PS/2 command interface was based on the AT interface, for which the typematic control commands were the same. The XT keyboard did not have a configurable autorepeat as far as I can tell. Note that typematic was implemented in the hardware, not in the BIOS.)

So at the end of the day, it all goes back to the 8042 keyboard controller chip. The hardware interface was reflected in the driver interface, which was reflected in the application interface. And when you issued the application call to change the keyboard autorepeat speed, that call went to the hardware; it was the hardware that actually did the autorepeating.

Since the semantics were codified in the application interface, they were locked into the SystemParametersInfo function even as the driver model and the keyboard hardware changed around it. (But I believe that if you're using a PS/2 keyboard, then the PS/2 keyboard driver will still defer the actual work of autorepeat to the physical hardware, so at least the semantics are still applicable.)

Comments (11)
  1. Pete says:

    The second link (http://www.computer-engineering.org/ps2keyboard/) leads to a 404. In fact, the entire computer-engineering.org website seems to be MIA…

    [Looks like the site went blooey recently (it’s still in search engine caches). Fortunately, it was captured by the Internet Archive. I’ve fixed the link, thanks. -Raymond]
  2. John says:

    The downside of writing blog entries years in advance.

  3. mvadu says:

    He has an upside too.. Getting headphones from coworkers 1.5 years after destroying one and writing about it. (which he posted recently).

  4. Alexander Grigoriev says:

    Almost like "What a space shuttle fuel tank size has to do with chariots of ancient Rome".

  5. CyberShadow says:

    That’s interesting, but how do the accessibility functions work then? By editing the keyboard accessibility registry options (HKCUControl PanelAccessibilityKeyboard Response), it’s possible to get a repeat rate up to ~60 CPM.

    [When FilterKeys is active, keyboard autorepeat is simulated in software. -Raymond]
  6. Thomas says:

    "But I believe that if you’re using a PS/2 keyboard, then the PS/2 keyboard driver will still defer the actual work of autorepeat to the physical hardware, so at least the semantics are still applicable."

    Judging by how various KVM switches behave, that sounds right. One brand flatly ignores the autorepeat setting from the computer and enforces its own. This means the computer setting does nothing, but behaviour is consistent across both attached computers (there’s a hotkey combination on the KVM to vary it). Another brand passes the autorepeat through unchanged and does not track it for each attached computer, which is annoying when the computers have different autorepeat settings (for added fun the second brand resets the PS/2 mouse when switching computer, and does not preserve mouse acceleration).

  7. Tom says:

    Alexander: Space shuttle boosters, not fuel tank.  The boosters are transported by rail — the fuel tank is barged in.  The connection is tenuous at best.  Snopes.com did a pretty good debunking/explanation.

    Aside from IBM, the Bell System is the other common source of long-lasting standards.  You’ll find a lot of telephone standards that have stuck around for compatibility reasons.

  8. Yuhong Bao says:

    "That document describes the PS/2 keyboard interface, but the PS/2 command interface was based on the AT interface, for which the typematic control commands were the same. "

    Yep, in fact electronically the PS/2 and AT keyboard interface was I think the same, so only a physical adapter was needed to convert between the two.

  9. Dinev says:

    I’m using a Turbo-Plus PS/2 keyboard, where there’s a "Turbo" key, which with a combo Turbo+F1 sets the repeat-rate to 1Hz, and Turbo+F7 to 31Hz.

    Low repeat-rates somehow delay the keypress detection a bit, though (70ms max, I have quick eyes). I’m not sure why.

  10. Worf says:

    @Dinev: Your keyboard is just offering a keyboard-accessible way to change the typematic rate, and it appears it also controls the delay (since it’s PS/2, the hardware generates the repeat).

    I believe the lowest setting is aroung 1-2 characters. and the highes is just over 30, which I guess your keyboard calls 1Hz and 31Hz, respectively. At the lowest settings it’s also probably using the 1 second delay, and at the highest, the .25 second. Both of which are controllable through the control panel…

Comments are closed.