How does the keyboard autorepeat setting work?

Raymond Chen

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.)


Discussion is closed.

Feedback usabilla icon