How can I increase the key repeat rate beyond the OS's limit?

Frank Krueger picture Frank Krueger · Oct 5, 2008 · Viewed 40.6k times · Source

I have a bad habit of using the cursor keys of my keyboard to navigate source code. It's something I've done for 15 years and this of course means that my navigating speed is limited by the speed of the keyboard. On both Vista and OS X (I dual boot a MacBook), I have my key repeat rate turned all the way up. But in Visual Studio, and other apps, the rate is still much slower than I would prefer.

How can I make the key repeat rate faster in Visual Studio and other text editors?

Answer

Mud picture Mud · Jun 15, 2012

In Windows you can set this with a system call (SystemParametersInfo(SPI_SETFILTERKEYS,...)).

I wrote a utility for myself: keyrate <delay> <repeat>.

Github repository.

Full source in case that link goes away:

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

BOOL parseDword(const char* in, DWORD* out)
{
   char* end;
   long result = strtol(in, &end, 10);
   BOOL success = (errno == 0 && end != in);
   if (success)
   {
       *out = result;
   }
   return success;
}


int main(int argc, char* argv[])
{
   FILTERKEYS keys = { sizeof(FILTERKEYS) };

   if (argc == 1)
   {
      puts ("No parameters given: disabling.");
   }
   else if (argc != 3)
   {
      puts ("Usage: keyrate <delay ms> <repeat ms>\nCall with no parameters to disable.");
      return 0;
   }
   else if (parseDword(argv[1], &keys.iDelayMSec) 
         && parseDword(argv[2], &keys.iRepeatMSec))
   {
      printf("Setting keyrate: delay: %d, rate: %d\n", (int) keys.iDelayMSec, (int) keys.iRepeatMSec);
      keys.dwFlags = FKF_FILTERKEYSON|FKF_AVAILABLE;
   }

   if (!SystemParametersInfo (SPI_SETFILTERKEYS, 0, (LPVOID) &keys, 0))
   {
      fprintf (stderr, "System call failed.\nUnable to set keyrate.");
   }

   return 0;
}