title: What is the best way to read input from keyboard using SDL?
body: <p>I'm running an <code>update()</code> method n times per second to &quot;update&quot; the keyboard input from the user so I can read it later in the logic part of the program. So I find two ways of implementing this in the SDL Docs and I'm not sure which one should I use.</p>
  <p>1; Loop for all events using SDL_PollEvent searching for key down/up events and saving the key states in a map so I can check for each key state in the logic of the program.</p>
  <p>Note: Alternatively, I can also use SDL_PeepEvents instead of SDL_PollEvent to take only the event types that matter; so, it would not &quot;thrown away&quot; the events on the queue.</p>
  <pre class="lang-cpp prettyprint-override"><code>std::map&lt;int, bool&gt; keyboard; // Saves the state(true=pressed; false=released) of each SDL_Key.
      
  void update()
  {
      SDL_Event event;
      while(SDL_PollEvent(&amp;event))
      {
          switch(event.type)
          {
              case SDL_KEYDOWN:
                  keyboard[event.key.keysym.sym] = false;
                  break;
              case SDL_KEYUP:
                  keyboard[event.key.keysym.sym] = true;
                  break;
          }
      }
  }
  </code></pre>
  <p>2; Taking a snapshot from the keyboard each frame so I can read it easily.</p>
  <pre class="lang-cpp prettyprint-override"><code>Uint8* keyboard;
      
  void update()
  {
      SDL_PumpEvents();
      keyboard = SDL_GetKeyState(NULL);
  }
  </code></pre>
  <p>With any of above implementations I can read <code>keyboard</code> just like this:</p>
  <pre class="lang-cpp prettyprint-override"><code>if (key_map[SDLK_Return]) printf(&quot;Return has been pressed.&quot;);
  </code></pre>
  <p>Also, is there another way to do so?</p>