1
votes

So I have the following code that listens for a keydown event and then exits as soon as it receives one:

int main(int argc, char** argv) {
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Surface* screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF);
    SDL_Event _event;
    while (1) {
        while (SDL_PollEvent(&_event)) {
            if (_event.type == SDL_KEYDOWN) {
                return 0;
            }
        }
        SDL_GL_SwapBuffers();
    }
}

When I run it, I can press any arrow key, letter, number, F1-F12... pretty much any key except for the left control key, and the program will exit instantly.
But when I press the left control key, the program doesn't exit until I release the key.

And although the example doesn't show it, pressing another key while left-control is being held down (eg ctrl+s) causes the missing control keydown event to be triggered (along with a second event that says 's' was pressed).

Is there any way to disable this strange behavior for the left-control key?

Btw, this is on Windows using mingw. I haven't tested this behavior with any other compilers/operating systems.

1
Have you tried SDL_WM_GrabInput?Piotr Praszmo
@Banthar I tried that, but all it did was trap the mouse.Ponkadoodle

1 Answers

1
votes

So it turns out that I had forgotten to put sdl.dll into the same directory as my executable. It was loading some other sdl.dll that happened to be on the path environment variable. I put the sdl.dll that matched the version I was compiling against (1.2.14) into my application's directory, and it works fine now.