Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setKeyRepeatEnabled #92

Open
zerodarkzone opened this issue Oct 31, 2023 · 1 comment
Open

setKeyRepeatEnabled #92

zerodarkzone opened this issue Oct 31, 2023 · 1 comment

Comments

@zerodarkzone
Copy link

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.

@fallahn
Copy link
Owner

fallahn commented Oct 31, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants