I want to write a C++ class that only handles input events. Whereas it’s
easy to write one that deals with the keyboard state (using
SDL_GetKeyState), it’s not so obvious how to write one that uses the
event model. Having one monolithic despatcher function that pulls any
event off the queue and sends them to the relevant subsystems doesn’t
fit my idea of a well encapsulated design, so I want to avoid that if
possible.
Basically I want to be able to be able to pick keypress events and no
others off the event queue, leaving other events to be handled by other
classes. What is the best way to do this? Do I need to pick events off,
check their type, and push them back if they’re not keypresses? Or
should I perhaps use SDL_SetEventFilter to grab the keypresses before
they even hit the queue and store them in a queue of my own instead?
In DirectInput I achieved this by storing a buffer of the last frame’s
input. While this worked reasonably well and was easy to implement, if a
key was pressed and released (or vice versa) within the space of a frame
it wouldn’t be recognised. And along the same lines, aliasing effects
could occur at slow frame rates when a key was pressed often in
succession.–
Kylotan