SDL 2.0 - SDL_GameControllerGetButton 不工作

SDL 2.0 - SDL_GameControllerGetButton not working

我正在开发一个应用程序,需要显示在操纵杆上按下了哪些按钮。

为此,我使用SDL读取我的摇杆状态,代码是:

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

出于某种原因,此函数始终 returns 0(假)。我也尝试过使用 SDL 事件(如图 here,但我也得到了相同的结果。

旁注:

我用来读取轴值的代码是:

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

有什么我遗漏的吗?

我设法通过从文件(例如 SDL_GameControllerDB)加载控制器映射来解决我的问题。

一些有用的链接: