Skip to content

SDL2: SDL_KeyboardEvent's "repeat" field does not get populated. #21378

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

Closed
giogadi opened this issue Feb 20, 2024 · 1 comment
Closed

SDL2: SDL_KeyboardEvent's "repeat" field does not get populated. #21378

giogadi opened this issue Feb 20, 2024 · 1 comment

Comments

@giogadi
Copy link

giogadi commented Feb 20, 2024

Possibly related to #21377.

When I hold a key down without releasing it, I would expect to start seeing SDL_KEYDOWN events with the repeat field set. I am seeing multiple SDL_KEYDOWN events, however the repeat field is still set to zero. Example:

SDL_Event e;
while (SDL_PollEvent(&e) != 0) {
    if (e.type == SDL_KEYDOWN) {
        if (e.key.repeat == 0) {
            printf("new key press\n");
        } else {
            printf("repeating\n");
        }
    }
}

When I hold a key down, I'd expect the console to say "new key press" and then spam "repeating". However, I just see lots of spam of "new key press", which means repeat is not being populated correctly.

I'm using Emscripten 3.1.54, which uses SDL 2.26.0. I'm compiling the code with the following command:

emcc main.c -o index.html -sUSE_SDL=2

I'm opening the generated page in Chrome Version 121.0.6167.160 on MacOS 11.7.10.

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.54 (a95c44ee924d02fa1498f846595485d27c31daa8)
clang version 19.0.0git (https://github.com/llvm/llvm-project e769fb8699e3fa8e40623764f7713bfc783b0330)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /Users/luis/code/emsdk/upstream/bin

Full link command and output with -v appended:
log.txt

@giogadi
Copy link
Author

giogadi commented Feb 21, 2024

The problem was that I was including the wrong SDL header: I needed to include <SDL.h>, not <SDL/SDL.h>.

@giogadi giogadi closed this as completed Feb 21, 2024
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

1 participant