问题
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?
回答1:
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.
回答2:
According to MSDN, it also looks like you could use the SystemParametersInfo function, and call use SPI_SETKEYBOARDSPEED, SPI_SETKEYBOARDDELAY.
回答3:
void Key_Set() { DWORD old = 0;
SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &old, 0);
SystemParametersInfo(SPI_SETKEYBOARDDELAY,0, &old, 0);
}
来源:https://stackoverflow.com/questions/1441423/change-repeat-key-threshold-c