crogine icon indicating copy to clipboard operation
crogine copied to clipboard

setKeyRepeatEnabled

Open zerodarkzone opened this issue 2 years ago • 1 comments

Hi,

xygine has a function called setKeyRepeatEnabled which can be used to avoid firing events when a key is pressed. It is used in the following way: getRenderWindow()->setKeyRepeatEnabled(false);

Does crogine has something similar? Right now if I left a key pressed, it keeps firing KEY_DOWN events.

zerodarkzone avatar Oct 31 '23 00:10 zerodarkzone

SDL2 handles this slightly differently - the key down event has a repeat field: https://wiki.libsdl.org/SDL2/SDL_KeyboardEvent

You'd do something like:

if (evt.type == SDL_KEYDOWN)
{
    if (!evt.key.repeat)
    {
        //handle event
    }
}

If it would be useful I could wrap this in a function to toggle repeated key presses by preventing any repeated events from being forward from the window.

fallahn avatar Oct 31 '23 09:10 fallahn