linux-keyboard.c: Fix 0 key contantly pressed on Linux

This commit is contained in:
Federico Amedeo Izzo 2021-01-01 20:41:15 +01:00
parent dba2b27310
commit 08087cb14a
1 changed files with 22 additions and 27 deletions

View File

@ -28,13 +28,9 @@ void kbd_init()
} }
keyboard_t kbd_getKeys() { keyboard_t kbd_getKeys() {
SDL_Event event;
keyboard_t keys = 0; keyboard_t keys = 0;
while ((SDL_PollEvent(&event)) != 0) { SDL_PumpEvents();
if (event.type == SDL_QUIT)
exit(0);
//Ignore all non-keyboard events
if (event.type != SDL_KEYDOWN) continue;
const uint8_t *state = SDL_GetKeyboardState(NULL); const uint8_t *state = SDL_GetKeyboardState(NULL);
if (state[SDL_SCANCODE_0]) keys |= KEY_0; if (state[SDL_SCANCODE_0]) keys |= KEY_0;
if (state[SDL_SCANCODE_1]) keys |= KEY_1; if (state[SDL_SCANCODE_1]) keys |= KEY_1;
@ -56,5 +52,4 @@ keyboard_t kbd_getKeys() {
if (state[SDLK_PLUS]) keys |= KEY_MONI; if (state[SDLK_PLUS]) keys |= KEY_MONI;
return keys; return keys;
} }
}