SDL事件查询函数:SDL_PeepEvents()

函数位置 :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;
} 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值