   Input handling
  I'm wondering how to handle input in my game. I figure that theres some layer of abstraction between SDL and the physics system that needs to know which way to point the rocket thruster, but I can't figur e out an easy way to do it. I could set up a whole mess of #defines for names of keys, set up a bool key[256] and then make each and every SDL_KEYWHATEVER point turn on or off a key[KEYWHATEVER], but I sense that there is a solution that doesn't involve quite so much work.   
  Searching these forums should give you a good start.  There have been a ton of threads like this one already.  As I'm heading out the door I don't have time to search right now but see what you can come up with.   ;  Note: [ source ] tags are BROKEN :(   ;  I'm not sure I understand your question, but the way I did it when I was using SDL was:void Input(){  // Bool values for whether or not keys are held down.  static bool DownPressed = false;  static bool UpPressed = false;  static bool LeftPressed = false;  static bool RightPressed = false;  // Fill the event structure  if(SDL_PollEvent(&gEvent))  {    // Handle user manually closing the window    if(gEvent.type == SDL_QUIT)    { // Game exiting code here. return; // Game over    }    // A key is pressed down    if(gEvent.type == SDL_KEYDOWN)    { /*ESC*/// Quit if(gEvent.key.keysym.sym == SDLK_ESCAPE) {   // Game exiting code here.   return; // Game over } if(gEvent.key.keysym.sym == SDLK_UP)   UpPressed = true; if(gEvent.key.keysym.sym == SDLK_DOWN)   DownPressed = true; if(gEvent.key.keysym.sym == SDLK_LEFT)   LeftPressed = true; if(gEvent.key.keysym.sym == SDLK_RIGHT)   RightPressed = true;    }    // A key is released.    if(gEvent.type == SDL_KEYUP)    { if(gEvent.key.keysym.sym == SDLK_UP)   UpPressed = false; if(gEvent.key.keysym.sym == SDLK_DOWN)   DownPressed = false; if(gEvent.key.keysym.sym == SDLK_LEFT)   LeftPressed = false; if(gEvent.key.keysym.sym == SDLK_RIGHT)   RightPressed = false;    }    // if(LeftPressed) move something left, or whatever logic here...  }}And I called that in my gameloop, before the rendering logic. This way also allows for holding a key down and having continuous movement.   ;  Hmm... its this sort of laundry list that I'm trying to avoid. It seems inevitable though. Anyone else got a solution?   ;Quote:Original post by NImHmm... its this sort of laundry list that I'm trying to avoid. It seems inevitable though. Anyone else got a solution?Use SDL_GetKeyState:unsigned char *keys = SDL_GetKeyState(NULL);if (keys[SDLK_UP]) ...if (keys[SDLK_ESCAPE])...And so on.  I'm in a hurry right now so all I have to say that this is a snapshot of the keyboard :).   ;  Here's how I would do it:Define a set of "action code" constants like Action_Move_Left, Action_Fire_Gun, and so onSet up a std::map that maps SDL keycodes to the action codesUse SDL_GetKeyState to fetch the keystate arrayLoop over the array; any time you find an entry that is set to True, see if there is a corresponding mapped Action Code in the std::map you set up earlierIf you can map from the keystate array to an action code, add that action code to a list of "current actions"Once the "current actions" list is built (I recommend a std::vector or something similar to hold it), pass that to a function that carries out each action.This has two advantages. First, and most obviously, it separates SDL input codes from your internal game logic, which is a good abstraction to put into place. Secondly, it lets you trivially support custom keymappings just by changing the contents of the std::map.   ;  Thank you all for your help and input.   