How do I use SDL_PeepEvents properly? |
August Karlstrom
Guest
|
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 http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||
|
How do I use SDL_PeepEvents properly? |
Gunther Van Butsele
Guest
|
Hi August,
Add SDL_PumpEvents() to your while loop
SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
How do I use SDL_PeepEvents properly? |
August Karlstrom
Guest
|
On 2014-10-10 11:50, Gunther Van Butsele wrote:
Thanks (again) Gunther. It works now.
SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||||
|