0

I am developing an application that needs to display which buttons are pressed on a joystick.

For this, I used SDL to read the state of my joysticks, the code is:

bool JoystickInfo::getButton (const int &joystick, SDL_GameControllerButton button)
{
    SDL_JoystickUpdate();
    gameController_ = SDL_GameControllerOpen (joystick);
    return (bool) SDL_GameControllerGetButton (gameController_, button);
}

For some reason, this function always returns 0 (false). I have also tried using the SDL events (as shown here, but I also got the same result.

Side-notes:

  • The code above worked fine with SDL 1.2, but I need SDL 2.0 for the GameController API.
  • I read the values of the axes of my joystick in a similar way and it works without any issue.
  • SDL_INIT() is called with SDL_INIT_EVERYTHING.

The code that I use for reading axis values is:

double JoystickInfo::getAxis (const int &joystick, SDL_GameControllerAxis axis)
{
    SDL_JoystickUpdate();
    gameController_ = SDL_GameControllerOpen (joystick);
    return (double) SDL_GameControllerGetAxis (gameController_, axis);
}

Is there something that I am missing?

Alex Spataru
  • 1,197
  • 4
  • 14
  • 26

1 Answers1

1

I managed to solve my issue by loading controller mappings from a file (such as the SDL_GameControllerDB).

Some useful links:

Alex Spataru
  • 1,197
  • 4
  • 14
  • 26