[SDL] Nervous about keyboard state usage
Erik
esigra at gmail.com
Sun Mar 16 03:38:37 PDT 2008
I get nervous when I see event handling code that that checks the state
of keys. It is such a common error to check the current key state (or
mouse position, ...) and get a result that is different from the state
when the handled event actually happened. (Not even KDE gets it right,
[http://bugs.kde.org/show_bug.cgi?id=151355].)
Therefore I wonder whether the following error might happen in an SDL
application:
1. 'X' key is pressed.
2. Control is pressed.
3. Application calls SDL_PollEvent, which calls SDL_PumpEvents. It sets
the state of the 'X' key to DOWN and the state of Control key to DOWN.
Then it returns the 'X' key press event to Application.
4. Application handles the 'X' key press event and the handler checks
the state of the Control key. SDL says it is DOWN, because that is the
current state. But it was not down when the handled event occurred, so
the result will be erroneous.
More information about the SDL
mailing list