Some event types not working

Hello,
I have a thread polling the event queue looking for SDL_KEYDOWN, SDL_KEYUP,
and SDL_QUIT event types. Unfortunately, these event types (as well as mouse
events) never seem to make it into the queue… I’m printing out the event type
of each event in the queue, and they’re all joystick or video events. I don’t
have any event filter set up. SDL_EventState reports that SDL_KEYDOWN events
are enabled, even though they never show up in the queue.
I basically copied this code from an earlier program I wrote, so I know it
works. The exception is that I’m using a joystick now. Does enabling the
joystick set up a filter for mouse & key events? Note that I’m not handling
the joystick with events, but with the GetAxis/GetButton functions.

Thanks for any ideas you might have!

Anthony Kolb

I cannot see what’s wrong without seeing the code, though I might guess you
broke the switch statement somehow. Could you provide a minimal example that
reproduces the problem?On Saturday 16 April 2005 15:06, Anthony Kolb wrote:

Hello,
I have a thread polling the event queue looking for SDL_KEYDOWN,
SDL_KEYUP, and SDL_QUIT event types. Unfortunately, these event types (as
well as mouse events) never seem to make it into the queue… I’m printing
out the event type of each event in the queue, and they’re all joystick or
video events. I don’t have any event filter set up. SDL_EventState
reports that SDL_KEYDOWN events are enabled, even though they never show up
in the queue.
I basically copied this code from an earlier program I wrote, so I know
it works. The exception is that I’m using a joystick now. Does enabling
the joystick set up a filter for mouse & key events? Note that I’m not
handling the joystick with events, but with the GetAxis/GetButton
functions.

Thanks for any ideas you might have!

Anthony Kolb

Tyler Montbriand <tsm accesscomm.ca> writes:

Hello,
I have a thread polling the event queue looking for SDL_KEYDOWN,
SDL_KEYUP, and SDL_QUIT event types. Unfortunately, these event types (as
well as mouse events) never seem to make it into the queue… I’m printing
out the event type of each event in the queue, and they’re all joystick or
video events. I don’t have any event filter set up. SDL_EventState
reports that SDL_KEYDOWN events are enabled, even though they never show up
in the queue.
I basically copied this code from an earlier program I wrote, so I know
it works. The exception is that I’m using a joystick now. Does enabling
the joystick set up a filter for mouse & key events? Note that I’m not
handling the joystick with events, but with the GetAxis/GetButton
functions.

Thanks for any ideas you might have!

Anthony Kolb
I cannot see what’s wrong without seeing the code, though I might guess you
broke the switch statement somehow. Could you provide a minimal example that
reproduces the problem?

Tyler,

The code for my event handler thread function looks like this:

int event_queue_thread_func(void *data){
SDL_Event event;
event = (SDL_Event
)data;
printf(“State of key events: %i\n”, SDL_EventState(SDL_KEYDOWN, SDL_QUERY));
while(current_mode != SHUTTING_DOWN){
while(SDL_PollEvent(event)){
printf(“Event type %i received.\n”, event->type);
switch( event->type ){
case SDL_KEYDOWN:
case SDL_KEYUP:
if(event->key.keysym.sym == SDLK_ESCAPE) printf(“Escape key
pressed.\n”);
exit(0);
break;
case SDL_QUIT:
exit(0);
break;
default:
break;
}
}
SDL_Delay(100);
}
return 0;
}

stdout.txt looks something like this:
State of key events: 1
Event type 17 received.
Event type 1 received.
Event type 7 received.
Event type 7 received.
Event type 7 received.
Event type 7 received.
Event type 7 received.
Event type 7 received.
etc…

Looking at the enumeration in SDL_events.h, type 17 is a SDL_VIDEOEXPOSE event,
1 is a SDL_ACTIVEEVENT event, and type 7 is a SDL_JOYAXISMOTION event. Note
that I was pushing keys and wiggling the joystick at the same time, but the key
events (types 2 & 3) don’t show up. The switch statement can’t be the problem,
because I’m printing out the type received before that. Again, SDL_EventState
reports that SDL_KEYDOWN events are enabled, and I don’t have a filter set up.

The only thing I’m doing different here than my other program (where this
worked) is using a joystick. That shouldn’t filter key events, right?

Thanks for the help,

Anthony Kolb> On Saturday 16 April 2005 15:06, Anthony Kolb wrote:

Tyler Montbriand <tsm accesscomm.ca> writes:

Hello,
I have a thread polling the event queue looking for SDL_KEYDOWN,
SDL_KEYUP, and SDL_QUIT event types. Unfortunately, these event types (as
well as mouse events) never seem to make it into the queue… I’m printing
out the event type of each event in the queue, and they’re all joystick or
video events. I don’t have any event filter set up. SDL_EventState
reports that SDL_KEYDOWN events are enabled, even though they never show up
in the queue.
I basically copied this code from an earlier program I wrote, so I know
it works. The exception is that I’m using a joystick now. Does enabling
the joystick set up a filter for mouse & key events? Note that I’m not
handling the joystick with events, but with the GetAxis/GetButton
functions.

Thanks for any ideas you might have!

Anthony Kolb
I cannot see what’s wrong without seeing the code, though I might guess you
broke the switch statement somehow. Could you provide a minimal example that
reproduces the problem?

I may have just found the answer to my question:


When I said all I was doing differently was the fact that I’d added a joystick,
I neglected to mention that in my previous program, I was polling the queue in
the main function, now I’m doing it in a thread. According to the link above,
that might not work in Windows. I’ll rework my program to poll the event queue
in main and see if that helps…

Anthony Kolb> On Saturday 16 April 2005 15:06, Anthony Kolb wrote:

Have you tried initializing SDL with the SDL_EVENTTHREAD flag?On Monday 18 April 2005 14:29, Anthony Kolb wrote:

I may have just found the answer to my question:
http://www.devolution.com/pipermail/sdl/2004-August/063947.html
When I said all I was doing differently was the fact that I’d added a
joystick, I neglected to mention that in my previous program, I was polling
the queue in the main function, now I’m doing it in a thread. According to
the link above, that might not work in Windows. I’ll rework my program to
poll the event queue in main and see if that helps…

Anthony Kolb

Tyler Montbriand <tsm accesscomm.ca> writes:

I may have just found the answer to my question:
http://www.devolution.com/pipermail/sdl/2004-August/063947.html
When I said all I was doing differently was the fact that I’d added a
joystick, I neglected to mention that in my previous program, I was polling
the queue in the main function, now I’m doing it in a thread. According to
the link above, that might not work in Windows. I’ll rework my program to
poll the event queue in main and see if that helps…

Anthony Kolb
Have you tried initializing SDL with the SDL_EVENTTHREAD flag?

Tyler,
I just tried your suggestion, and my program quit instantly with the
message, “Couldn’t initialize SDL: OS doesn’t support threaded events”. This
is in Win2K. So, I guess that means I need to poll the event queue in main,
not in a thread? I still don’t understand why some event types worked, and not
others.
Thanks for the ongoing help!

Anthony> On Monday 18 April 2005 14:29, Anthony Kolb wrote:

Very odd! I was sure Windows supported this, but on finding a windows box to
test on, apparently it doesn’t! I guess this kind of weirdness is why.

As for the reason for the weirdness, windows seems chock full of fun stuff
like that. Did you know that sound output won’t work under
windows unless you’ve set the video mode? It’ll act like it’s working but
just play silence.On Tuesday 19 April 2005 10:12, Anthony Kolb wrote:

Tyler,
I just tried your suggestion, and my program quit instantly with the
message, “Couldn’t initialize SDL: OS doesn’t support threaded events”.
This is in Win2K. So, I guess that means I need to poll the event queue in
main, not in a thread? I still don’t understand why some event types
worked, and not others.
Thanks for the ongoing help!

Anthony