Alt tab release (#1460)

* added reset keyboard during release_keys

* trigger a key-up on all scancodes
This commit is contained in:
Dimitris Panokostas 2024-10-04 19:05:31 +02:00 committed by GitHub
parent aada2f3e69
commit b5129e7aa0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -760,16 +760,31 @@ static void close_kb()
void release_keys(void)
{
SDL_PumpEvents();
// only run this if SDL2 version is 2.24 or higher
#if SDL_VERSION_ATLEAST(2,0,24)
SDL_ResetKeyboard();
#else
{
const Uint8* state = SDL_GetKeyboardState(NULL);
SDL_Event event;
//for (int j = 0; j < MAX_INPUT_DEVICES; j++) {
// for (int i = 0; i < MAX_KEYCODES; i++) {
// if (di_keycodes[j][i]) {
// di_keycodes[j][i] = 0;
// my_kbd_handler(j, i, 0, true);
// }
// }
//}
for (int i = 0; i < SDL_NUM_SCANCODES; ++i) {
if (state[i]) {
event.type = SDL_KEYUP;
event.key.keysym.scancode = (SDL_Scancode)i;
event.key.keysym.sym = SDL_GetKeyFromScancode((SDL_Scancode)i);
event.key.keysym.mod = 0;
event.key.state = SDL_RELEASED;
SDL_PushEvent(&event);
}
}
}
#endif
for (int j = 0; j < MAX_INPUT_DEVICES; j++) {
for (int i = 0; i < SDL_NUM_SCANCODES; i++) {
my_kbd_handler(j, i, 0, true);
}
}
}
static int acquire_kb(const int num, int flags)