This is a simple way of handling input events. Are you already doing it this way?
Your main game loop (greatly simplified):
Code:
while(runMainGameLoop) {
while(SDL_PollEvent(&event)) {
eventHandler(&event);
}
yourLogicFunction();
yourRenderFunction();
}
In the code above, you just replace "eventHandler" with whatever function you want to pass your events to.
Once you've done this, you just need to respond to events properly in this function. If all you need is a regular keypress, an example such as the following would work :
Code:
eventHandler(SDL_Event* event) {
if(event->type == SDL_KEYDOWN) {
if(event->key.keysym.sym == SDLK_UP) { //this would be if the UP arrow key is pressed
//do something
}
}
}
A nicer way of doing this however would be with a switch statement:
Code:
eventHandler(SDL_Event* event) {
switch(event->type) {
case SDL_KEYDOWN: {
//handle events for individual keypresses here
break;
}
//insert additional cases for other event types below (e.g keyup, mousemotion, etc)
}
}
You may already be doing this in which case the last 15 minutes of my life have been wasted XD
But if you're following the procedure above your events should be listened to correctly.
If you don't already do this, it can be wise to write a main event class which has virtual functions (create blank functions functions) in it for all the events you need to respond to. Then if you inherit this class in your other classes you just need to override (redefine) the functions you need from that event class. This will give you a flexible way of handling the same input easily in different classes without having to mess around. You'll just need to create an event handler function in each class that uses it that simply calls the main event handler function from your event handling class and passes the event object in. The switch statement from my above examples would go in the main class and just call a relevant function in the class each time an event is actioned.
Phew.. hope that made sense

Let me know if this is any help or if you have anymore questions. If you're still stuck, post your code and I'll have a look.