tags:

views:

98

answers:

3

Basically, when one types, a keydown event happens. If the key is held for more than a certain time (~1 sec) then the key is repeatedly pressed until keyup hapens. I would like to change the time it takes for the key to be automatically repressed in my c++ application. How can this be done?

Thanks

+3  A: 

The speed at which a keypress becomes automatically recurring is controlled by Windows.

If you want to manipulate automatic recurrences of key-presses, it might be more advantageous to poll for the state of the key rather than waiting for the keydown event. It depends on how responsive you need your application to be.

This article may help you in figuring out how to query for key states: link

Stuart Thompson
A: 

A simple way to handle this is to establish a buffer of time around the OnKeyDown event. Setup a timer that determines whether control passes to a secondary event handler. If the timer has expired, then it is OK to pass control. If the timer hasn't expired, then you should return and leave the event unhandled. Start the timer right before passing control to your secondary event handler.

void KeyDownHandler(...)
{
    // ...
    if (TimeLeft() <= 0)
    {
        StartTimer();
        handleKeyDown();
    }
}

A timer is better than counting duplicate events because you can't assume that a given system will have the same repeat rate set as yours.

I agree with Stuart that polling for the state of the key might work better. It depends upon what you are trying to accomplish.

Also note that this type of behavior might be highly annoying to your user - why do you need to ignore duplicates?

Will Bickford
A: 

Use SetKeySpeed api (Kernel)