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

前端 未结 15 2101
攒了一身酷
攒了一身酷 2021-01-29 21:16

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

15条回答
  •  忘了有多久
    2021-01-29 21:47

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

    I wrote a utility for myself: keyrate .

    Github repository.

    Full source in case that link goes away:

    #include 
    #include 
    #include 
    
    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  \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;
    }
    

提交回复
热议问题