title: SDL 2.0 - SDL_GameControllerGetButton not working
body: <p>I am developing an application that needs to display which buttons are pressed on a joystick.</p>
  
  <p>For this, I used SDL to read the state of my joysticks, the code is:</p>
  
  <pre><code>bool JoystickInfo::getButton (const int &amp;joystick, SDL_GameControllerButton button)
  {
      SDL_JoystickUpdate();
      gameController_ = SDL_GameControllerOpen (joystick);
      return (bool) SDL_GameControllerGetButton (gameController_, button);
  }
  </code></pre>
  
  <p>For some reason, this function always returns 0 (false). I have also tried using the SDL events (as shown <a href="http://blog.5pmcasual.com/game-controller-api-in-sdl2.html" rel="nofollow">here</a>, but I also got the same result.</p>
  
  <p>Side-notes:</p>
  
  <ul>
  <li>The code above worked fine with SDL 1.2, but I need SDL 2.0 for the <code>GameController</code> API.</li>
  <li>I read the values of the axes of my joystick in a similar way and it works without any issue.</li>
  <li><code>SDL_INIT()</code> is called with <code>SDL_INIT_EVERYTHING</code>.</li>
  </ul>
  
  <p>The code that I use for reading axis values is:</p>
  
  <pre><code>double JoystickInfo::getAxis (const int &amp;joystick, SDL_GameControllerAxis axis)
  {
      SDL_JoystickUpdate();
      gameController_ = SDL_GameControllerOpen (joystick);
      return (double) SDL_GameControllerGetAxis (gameController_, axis);
  }
  </code></pre>
  
  <p>Is there something that I am missing?</p>