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