   SDL is overflowing keys?
  I've searched around and haven't found anything that helps me. In my game, I have an inventory system. Everytime the user switches to a different slot via the keyboard, a sound plays. This sound is short, not even a second long. However, when I press right, left, right quickly, and I have released the keys, it still does the right left right and I can't do anything until it's done. Is there a way to stop doing stuff if I release the keys? Here's the snippet that I'm having problems with:SDL_PollEvent(&events);switch (events.type){case SDL_KEYDOWN:switch (events.key.keysym.sym){case SDLK_i:play_sound("SFX\\invclose.ogg");InInv = false;SDL_Delay(200);break;case SDLK_LEFT:if (CursorX <= 290){break;}else if (CursorX > 290){play_sound("SFX\\nav.ogg");CursorX -= 35;CursorItem -= 1;SDL_Delay(50);}break;case SDLK_RIGHT:if (CursorX >= 535){break;}else if (CursorX < 535-35){play_sound("SFX\\nav.ogg");CursorX += 35;CursorItem += 1;SDL_Delay(50);}break;case SDLK_UP:if (CursorY <= 33){break;}else if (CursorY < 535){play_sound("SFX\\nav.ogg");CursorY -= 35;CursorItem -= 7;SDL_Delay(50);}break;case SDLK_DOWN:if (CursorY >= 278){break;}else if (CursorY < 278-35){play_sound("SFX\\nav.ogg");CursorY += 35;CursorItem += 7;SDL_Delay(50);}break;case SDLK_RETURN:play_sound("SFX\\open_nav.ogg");DisplayOptions(CursorX, CursorY, CursorItem);break;}break;case SDL_KEYUP:break;}
  I guess you could try this:// If this is truejust ignore all further events.bool ignore = false;// Maybe this?/*if (still playing music){  ignore = true;}*/while(SDL_PollEvent(&event) && !ignore){  switch (events.type)  {    case SDL_KEYDOWN: switch (events.key.keysym.sym) {case SDLK_i:    play_sound("SFX\\invclose.ogg");  InInv = false;ignore = true;  //SDL_Delay(200);  break;case SDLK_LEFT:  if (CursorX <= 290)  {  break;  }  else if (CursorX > 290)  {  play_sound("SFX\\nav.ogg");  ignore = true;    CursorX -= 35;   CursorItem -= 1;    //SDL_Delay(50);  }  break;case SDLK_RIGHT:  if (CursorX >= 535)  {    break;}  else if (CursorX < 535-35)  {    play_sound("SFX\\nav.ogg");  ignore = true;    CursorX += 35;    CursorItem += 1;    //SDL_Delay(50);  }  break;case SDLK_UP:  if (CursorY <= 33)  {    break;  }  else if (CursorY < 535)  {    play_sound("SFX\\nav.ogg");  ignore = true;    CursorY -= 35;    CursorItem -= 7;    //SDL_Delay(50);   }   break;case SDLK_DOWN:   if (CursorY >= 278)   {   break;   }   else if (CursorY < 278-35)   {play_sound("SFX\\nav.ogg");   ignore = true;CursorY += 35;CursorItem += 7;//SDL_Delay(50);   }   break; case SDLK_RETURN:   play_sound("SFX\\open_nav.ogg"); ignore = true;   DisplayOptions(CursorX, CursorY, CursorItem);   break;  }  break;case SDL_KEYUP:  break;   }}Just ignore any events that occur after an event until your done playing the music.   ;  It seemed to help a little bit, but are you sure you're understanding the question? When I press left, right, left, the game will do the first left and when I lift my fingers from the keys, it still executes right then the second left.   ;  you could try doing something like this, which would only handle each button only being pressed once.bool left_pressed=false,right_pressed=false, (etc....);//other codewhile (!done){//other stuffswitch (events.type){case SDL_KEYDOWN:switch (events.key.keysym.sym){case SDLK_LEFT:  { left_pressed=true;}break;  case SDLK_RIGHT: //etc....  }break;    case SDL_KEYUP:    {   if (left_pressed) //handle left arrow {if (CursorX <= 290){break;}else if (CursorX > 290){play_sound("SFX\\nav.ogg");CursorX -= 35;CursorItem -= 1;SDL_Delay(50);} left_pressed=false;}   if (right_pressed) //handle right arrow}break; }};  I just quickly skimmed over your code, but I believe you need to do something like this:while(SDL_PollEvent(&ev)){  //handle event}so you get all the events in the event queue. Your code looks like it only reads one event, so lots of events will get pushed into the queue, and you'll only read one event (per frame).SDL_PollEvent will return 0 when the queue of events is empty, which will exit the while loop.   ;  Neither of your suggestions worked. flashingchicken's way randomly got the arrow stuck, and when you pressed 'i' the inventory would close, then open again. wyrzy's method did not work at all. I could get into the inventory, then nothing would happen. I can give you guys a link to the demo if you want to check out the problem in real time.   ;  I can think of two potential workarounds:1) Use SDL_KeyUp instead of SDL_KeyDown events2) Increase the repeat time of SDL_KeyDown, using SDL_EnableKeyRepeat;Quote:Original post by orcfan32Neither of your suggestions worked. flashingchicken's way randomly got the arrow stuck, and when you pressed 'i' the inventory would close, then open again. wyrzy's method did not work at all. I could get into the inventory, then nothing would happen. I can give you guys a link to the demo if you want to check out the problem in real time.If you look at the some SDL docs, you'll see that you need to do "while(SDL_PollEvent(&ev))" to remove all the events from the queue.See: http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_project_en/sdlpollevent.html(this is also in the "docs" folder that comes with SDL)SDL_Event event; /* Event structure */.../* Check for events */while(SDL_PollEvent(&event)){  /* Loop until there are no events left on the queue */  switch(event.type){  /* Process the appropiate event type */    case SDL_KEYDOWN:  /* Handle a KEYDOWN event */printf("Oh! Key press\n"); break;    case SDL_MOUSEMOTION: . . .    default: /* Report an unhandled event */ printf("I don't know what this event is!\n");  }}EDIT:By the way, if you can't get that to work, you can also use SDL_PollEvent and SDL_GetKeyState and check the state of the keys asynchronously (sp). They should also be listed in the SDL docs.   ;  A suggestion might be to switch from using SDL_PollEvent to SDL_WaitEvent.  I use to have the same problem where the key's went way to fast but I switched it to using a mixture of SDL_Wait (for key presses) and SDL_Poll for getting mouse positions, also make sure you are using the same SDL_Event variable, I learned that if you create several that the last one you reference goes through everything correctly but the previous one's instanced also go through the same events (and I tried flushing it and all kind's of stuff like that, but never could get it to work right).  Like I said, just an idea though (I use CTRL to skip text, using SDL wait it works fine, BUT it only allows it to go once even if you hold it down, until you move the mouse or basically create another event, hence why I used both SDL_Wait for the keyboard and also used SDL_Poll for the mouse).  Just a thought but I think this might help out a bit more if all you need is a single keypress rather than a million (another though is to use SDL_Delay which does work to a degree but I hear this doesn't work on linux).EsperKnight   