函数位置 :SDL_events.h
函数原型:extern DECLSPEC int SDLCALLSDL_PeepEvents(SDL_Event *events, int numevents,SDL_eventaction action, Uint32mask);
功能 :从事件队列中搜寻相对应的事件,但事件本身仍然在事件队列中。
Description
Checks the eventqueue for messages and optionally returns them.
Return Value
This functionreturns the number of events actually stored, or -1 if there was an error.
SDL_eventaction action
typedef enum {
SDL_ADDEVENT,
SDL_PEEKEVENT,
SDL_GETEVENT
} SDL_eventaction;
If action isSDL_ADDEVENT, up to numevents events will be added to the back of the eventqueue.
If action isSDL_PEEKEVENT, up to numevents events at the front of the event queue, matchingmask, will be returned and will not be removed from the queue.
If action isSDL_GETEVENT, up to numevents events at the front of the event queue, matchingmask, will be returned and will be removed from the queue.
This function isthread-safe.
Uint32 mask
对应sdl里的SDL_EventMask,如字意
typedef enum {
SDL_ACTIVEEVENTMASK =SDL_EVENTMASK(SDL_ACTIVEEVENT),
SDL_KEYDOWNMASK =SDL_EVENTMASK(SDL_KEYDOWN),
SDL_KEYUPMASK =SDL_EVENTMASK(SDL_KEYUP),
SDL_KEYEVENTMASK =SDL_EVENTMASK(SDL_KEYDOWN)|
SDL_EVENTMASK(SDL_KEYUP),
SDL_MOUSEMOTIONMASK =SDL_EVENTMASK(SDL_MOUSEMOTION),
SDL_MOUSEBUTTONDOWNMASK =SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN),
SDL_MOUSEBUTTONUPMASK =SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
SDL_MOUSEEVENTMASK =SDL_EVENTMASK(SDL_MOUSEMOTION)|
SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)|
SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
SDL_JOYAXISMOTIONMASK =SDL_EVENTMASK(SDL_JOYAXISMOTION),
SDL_JOYBALLMOTIONMASK =SDL_EVENTMASK(SDL_JOYBALLMOTION),
SDL_JOYHATMOTIONMASK =SDL_EVENTMASK(SDL_JOYHATMOTION),
SDL_JOYBUTTONDOWNMASK =SDL_EVENTMASK(SDL_JOYBUTTONDOWN),
SDL_JOYBUTTONUPMASK =SDL_EVENTMASK(SDL_JOYBUTTONUP),
SDL_JOYEVENTMASK =SDL_EVENTMASK(SDL_JOYAXISMOTION)|
SDL_EVENTMASK(SDL_JOYBALLMOTION)|
SDL_EVENTMASK(SDL_JOYHATMOTION)|
SDL_EVENTMASK(SDL_JOYBUTTONDOWN)|
SDL_EVENTMASK(SDL_JOYBUTTONUP),
SDL_VIDEORESIZEMASK =SDL_EVENTMASK(SDL_VIDEORESIZE),
SDL_VIDEOEXPOSEMASK =SDL_EVENTMASK(SDL_VIDEOEXPOSE),
SDL_QUITMASK =SDL_EVENTMASK(SDL_QUIT),
SDL_SYSWMEVENTMASK =SDL_EVENTMASK(SDL_SYSWMEVENT)
} SDL_EventMask ;
#defineSDL_ALLEVENTS 0xFFFFFFFF
例程:
这个最常用的API是由其他API实现的:
int SDL_PollEvent(SDL_Event *event )
{
SDL_PumpEvents ();
/* We can't return -1, just return 0 (no event) on error */
if ( SDL_PeepEvents (event , 1, SDL_GETEVENT , SDL_ALLEVENTS ) <= 0 ) //SDL_ALLEVENTS位于SDL_EventMask下
return 0;
return 1;
}