How do I use SDL_PeepEvents properly?

When I call the function PeekEvents below the program never halts even
though I type on the keyboard when the SDL window has focus. Why doesn’t
SDL_PeepEvents catch my keystrokes?

void PeekEvents(void)
{
SDL_Event events[1];
int count;

 do {
     count = SDL_PeepEvents(events, LEN(events), SDL_PEEKEVENT, 

SDL_EVENTMASK(SDL_KEYDOWN));
} while (count == 0);
printf("%d\n", count);
}

Here is the complete program:

#include <SDL/SDL.h>
#include <stdio.h>

#define LEN(a) ((int) (sizeof (a) / sizeof (a)[0]))

static void PeekEvents(void)
{
SDL_Event events[1];
int count;

 do {
     count = SDL_PeepEvents(events, LEN(events), SDL_PEEKEVENT, 

SDL_EVENTMASK(SDL_KEYDOWN));
printf("%d\n", count);
} while (count == 0);
}

static void Init(int *error)
{
SDL_Surface *display;

 *error = SDL_Init(SDL_INIT_VIDEO);
 if (! *error) {
     display = SDL_SetVideoMode(640, 480, 8, 0);
     if (display != NULL) {
         *error = 0;
     } else {
         fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError());
         *error = 1;
     }
 } else {
     fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
     *error = 1;
 }

}

int main(void)
{
int error;

 Init(&error);
 if (! error) {
     PeekEvents();
 }
 return error;

}

– August

Hi August,

Add SDL_PumpEvents() to your while loop> -----Original Message-----

From: SDL [mailto:sdl-bounces at lists.libsdl.org] On Behalf Of August
Karlstrom
Sent: vrijdag 10 oktober 2014 8:57
To: sdl at lists.libsdl.org
Subject: [SDL] How do I use SDL_PeepEvents properly?

When I call the function PeekEvents below the program never halts even
though I type on the keyboard when the SDL window has focus. Why doesn’t
SDL_PeepEvents catch my keystrokes?

void PeekEvents(void)
{
SDL_Event events[1];
int count;

 do {
     count = SDL_PeepEvents(events, LEN(events), SDL_PEEKEVENT,

SDL_EVENTMASK(SDL_KEYDOWN));
} while (count == 0);
printf("%d\n", count);
}

Here is the complete program:

#include <SDL/SDL.h>
#include <stdio.h>

#define LEN(a) ((int) (sizeof (a) / sizeof (a)[0]))

static void PeekEvents(void)
{
SDL_Event events[1];
int count;

 do {
     count = SDL_PeepEvents(events, LEN(events), SDL_PEEKEVENT,

SDL_EVENTMASK(SDL_KEYDOWN));
printf("%d\n", count);
} while (count == 0);
}

static void Init(int *error)
{
SDL_Surface *display;

 *error = SDL_Init(SDL_INIT_VIDEO);
 if (! *error) {
     display = SDL_SetVideoMode(640, 480, 8, 0);
     if (display != NULL) {
         *error = 0;
     } else {
         fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError());
         *error = 1;
     }
 } else {
     fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
     *error = 1;
 }

}

int main(void)
{
int error;

 Init(&error);
 if (! error) {
     PeekEvents();
 }
 return error;

}

– August


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Add SDL_PumpEvents() to your while loop

Thanks (again) Gunther. It works now.On 2014-10-10 11:50, Gunther Van Butsele wrote:

-----Original Message-----
From: SDL [mailto:sdl-bounces at lists.libsdl.org] On Behalf Of August
Karlstrom
Sent: vrijdag 10 oktober 2014 8:57
To: sdl at lists.libsdl.org
Subject: [SDL] How do I use SDL_PeepEvents properly?

When I call the function PeekEvents below the program never halts even
though I type on the keyboard when the SDL window has focus. Why doesn’t
SDL_PeepEvents catch my keystrokes?

void PeekEvents(void)
{
SDL_Event events[1];
int count;

  do {
      count = SDL_PeepEvents(events, LEN(events), SDL_PEEKEVENT,

SDL_EVENTMASK(SDL_KEYDOWN));
} while (count == 0);
printf("%d\n", count);
}

Here is the complete program:

#include <SDL/SDL.h>
#include <stdio.h>

#define LEN(a) ((int) (sizeof (a) / sizeof (a)[0]))

static void PeekEvents(void)
{
SDL_Event events[1];
int count;

  do {
      count = SDL_PeepEvents(events, LEN(events), SDL_PEEKEVENT,

SDL_EVENTMASK(SDL_KEYDOWN));
printf("%d\n", count);
} while (count == 0);
}

static void Init(int *error)
{
SDL_Surface *display;

  *error = SDL_Init(SDL_INIT_VIDEO);
  if (! *error) {
      display = SDL_SetVideoMode(640, 480, 8, 0);
      if (display != NULL) {
          *error = 0;
      } else {
          fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError());
          *error = 1;
      }
  } else {
      fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
      *error = 1;
  }

}

int main(void)
{
int error;

  Init(&error);
  if (! error) {
      PeekEvents();
  }
  return error;

}

– August


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org