Setting the Windows keyboard speed
Shows you how to set the keyboard repeat rate using Win32.
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;Related Tutorials
Balancing Game Development and Creative Direction in Indie Production
A practical look at how indie developers can balance creative direction with hands-on game development. This article co…
My Unreal Engine Development Process: From Core Idea to Playable Build
A practical overview of my Unreal Engine development process, covering how I move from a core game idea to a playable b…
Introducing LaneGraph: The Ultimate Road Network Solution for Unity
Discover the power of LaneGraph, a lightweight and flexible lane-based navigation system for Unity. LaneGraph makes it…
Retargeting Mixamo Characters with Root Motion In Unreal Engine 5.4.
I have always found Retargeting Mixamo Characters To have Root Motion is a serious lengthy Tast, Recently I stumbled up…
How To Make A SIMPLE Main Menu In Unity
In this tutorial for unity, i go over how to make a simple main menu for unity, it's an unlisted video because i do not…
Guide to Gameplay Balance
A perspective on competitive gameplay balance, from a background of "shooter" sandbox design.
Discussion
More from Matthew Allen
Comparing Shadow Mapping Techniques with Shadow Explorer
New Incentives and a Whole New Platform From The Intel AppUp developer program
The final installment in this series on Intel's AppUp program details additional incentives and opportunities for devel…
The Game Maker
This book excerpt contains the first chapter of the book that introduces beginning game developers to the Game Maker pr…
Discussion