tags:

views:

314

answers:

3

I'm building a c++ tetris game (not c++ .Net). I feel my controls are weird. I want to make it so that when user presses one of the arrow keys, about 10ms of holding it down will start the repeat function windows has. It is set to about 500ms by default, and it is too laggy for my game. How can I set the speed at which it changes from the keydown to the repeat keydown? Not how many times / sec it repeats.

Thanks

*what I want to do is change the repeat delay to short

In control panel in keyboard settings there is repeat rate, how do i set this?

+6  A: 

Typically what you would do for this is instead of reacting to the WM_CHAR message that is subject to the normal key repeat settings, you would look for WM_KEYDOWN and WM_KEYUP, and take action based on a timer that you've got running. If you set the timer to fire every 50 ms for example, then you can repeat every 50 ms and still take the first action immediately when you get the WM_KEYDOWN message.

Greg Hewgill
That said, this is probably a better practice than changing around system settings programmatically.
sheepsimulator
A: 

According to MSDN, it also looks like you could use the SystemParametersInfo function, and call use SPI_SETKEYBOARDSPEED, SPI_SETKEYBOARDDELAY.

sheepsimulator
While it's possible to change the user's settings in this way, I would find it unacceptable for a single application to modify the way *I* like my keyboard repeat settings configured.
Greg Hewgill
Just insure old settings are reset when appilcation closes
Milo
Seriously, don't do this. I would be very angry if any application changed any personal settings I had.
GMan
@unknown: And if your application crashes before it gets a chance to do so? If the computer unexpectedly powers off? This is just a poor solution.
GMan
Or if I switch to another application while yours is still running?
Greg Hewgill
@ Greg, GMan - With great power comes great responsibility. Your'e just going to have to trust he'll use the least invasive solution to the users. There's hundreds of instances like this in Win32. Greg made his argument, I think its a good one.
sheepsimulator
A: 

void Key_Set() { DWORD old = 0;

SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &old, 0);


SystemParametersInfo(SPI_SETKEYBOARDDELAY,0, &old, 0);

}

Milo
**Don't do this.** Why should your application be so important as to change settings on my computer? Just use the proper message, as Greg has shown.
GMan