Jump to content
  • Advertisement
  • 07/05/00 03:36 PM
    Sign in to follow this  

    Setting the Windows keyboard speed

    General and Gameplay Programming

    Myopic Rhino
    updated: 11/9/99

    If you're using Windows messages for your keyboard input in a game, you'll either have to deal with whatever repeat rate the user has set for his machine or you'll have to set it for yourself. Luckily, setting it is extremely easy, so I'll just give you the code and let you learn from that. Be sure to restore the user's values before you exit your program!

    // VARIABLES
    int nKBDelay; // The old keyboard delay.
    DWORD nKBSpeed; // The old keyboard repeat speed.

    // SET NEW SPEED

    // Get the old keyboard repeat delay.
    // We need this so we can restore the users settings when the program exits.
    if ( SystemParametersInfo( SPI_GETKEYBOARDDELAY, 0,
    &nKBDelay, 0 ) == FALSE )
    return FALSE;

    // Get the old keyboard repeat speed.
    if ( SystemParametersInfo( SPI_GETKEYBOARDSPEED, 0,
    &nKBSpeed, 0 ) == FALSE )
    return FALSE;

    // Set the keyboard repeat delay to the shortest possible.
    // This is the number '0'. This value can be between 0 and 3.
    // 0 = 250 ms delay, 3 = 1 second (1000 ms) delay.
    if ( SystemParametersInfo( SPI_SETKEYBOARDDELAY, 0, NULL,
    SPIF_UPDATEINIFILE ) == FALSE )
    return FALSE;

    // Set the keyboard repeat speed to the fastest possible.
    // This is the '31' below. It can be any number between 0 and 31,
    // 0 = 2.5 repetitions per second, 31 = 31 repetitions per second.
    if ( SystemParametersInfo( SPI_SETKEYBOARDSPEED, 31, NULL,
    SPIF_UPDATEINIFILE ) == FALSE )
    return FALSE;

    // RESTORE USER'S SPEED

    // Reset the keyboard speeds.
    if ( SystemParametersInfo( SPI_SETKEYBOARDDELAY, nKBDelay, NULL,
    SPIF_UPDATEINIFILE ) == FALSE )
    return FALSE;

    if ( SystemParametersInfo( SPI_SETKEYBOARDSPEED, nKBSpeed, NULL,
    SPIF_UPDATEINIFILE ) == FALSE )
    return FALSE;


      Report Article
    Sign in to follow this  


    User Feedback


    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!