Only allow one pending keyboard event for any given key
This commit is contained in:
parent
3cd988bc3a
commit
b5cb693317
@ -14,6 +14,7 @@ struct
|
||||
SDL_TimerID timer_id;
|
||||
SDL_Keycode keysym;
|
||||
bool pressed;
|
||||
bool event_pending;
|
||||
} Key_Statuses[SDL_NUM_SCANCODES];
|
||||
|
||||
/**
|
||||
@ -174,15 +175,19 @@ void Window::run_event_loop()
|
||||
Uint32 Key_Repeat(Uint32 interval, void * param)
|
||||
{
|
||||
if (Key_Statuses[(uintptr_t)param].pressed)
|
||||
{
|
||||
if (!Key_Statuses[(uintptr_t)param].event_pending)
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
event.user.code = 0;
|
||||
event.user.data1 = (void *)(uintptr_t)Key_Statuses[(uintptr_t)param].keysym;
|
||||
event.user.data2 = nullptr;
|
||||
event.user.data2 = param;
|
||||
event.type = SDL_USEREVENT;
|
||||
|
||||
SDL_PushEvent(&event);
|
||||
Key_Statuses[(uintptr_t)param].event_pending = true;
|
||||
}
|
||||
|
||||
return 25u;
|
||||
}
|
||||
@ -238,6 +243,7 @@ void Window::handle_event(SDL_Event & event)
|
||||
break;
|
||||
|
||||
case SDL_USEREVENT:
|
||||
Key_Statuses[(uintptr_t)event.user.data2].event_pending = false;
|
||||
handle_keysym((uint32_t)(uintptr_t)event.user.data1);
|
||||
break;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user