[SDL] Nervous about keyboard state usage

Erik esigra at gmail.com
Sun Mar 16 15:43:21 PDT 2008


Sam Lantinga skrev:
>> The event systems gives you the history of key presses and releases while
>> the state checking functions give you the *current* state. They can not be
>> mixed because the concept of time used by the two mechanisms is completely
>> different.The events may be very old by the time you processes them while
>> the status functions give you state of the keys as they are right now.  If
>> you want to see if control and X are both pressed *right now* use the status
>> functions to test the current state of both keys. If you want to see the
>> history of presses and releases then use the event functions.
>>     
>
> This is also why key events have the modifier state at the time of the
> keypress, since it might be different than the current state.
That is what I had hoped for. I have now fixed all keyboard event 
handlers in our project. But unfortunately I was unable to find the 
modifier key state in mouse events in SDL 1.2.13. SDL_event is just a 
discriminated union with "Uint8 type" as the discriminator and a 
SDL_MouseButtonEvent in case it is a mouse button event. And 
SDL_MouseButtonEvent only has these members:
    Uint8 type;    /* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
    Uint8 which;    /* The mouse device index */
    Uint8 button;    /* The mouse button index */
    Uint8 state;    /* SDL_PRESSED or SDL_RELEASED */
    Uint16 x, y;    /* The X/Y coordinates of the mouse at press time */


I do not see anything there that could contain the state of the Ctrl and 
Shift keys.



More information about the SDL mailing list