如何在Mac上使用SDL的操纵杆?

时间:2014-11-20 22:17:43

标签: macos sdl osx-mavericks joystick

来源非常基础:

#include <SDL.h>

int main(int argc, char *argv[])
{
  if (SDL_Init(SDL_INIT_JOYSTICK))
  {
    return 1;
  }
  int num_joy, i;
  num_joy=SDL_NumJoysticks();
  printf("%d joysticks found\n", num_joy);
  for(i=0;i<num_joy;i++)
      printf("%s\n", SDL_JoystickName(i));

  SDL_Quit();
  return 0;
}

这将输出Ubuntu 12.04上已连接操纵杆的名称,但不会在我的Mavericks Mac上输出,其中SDL 1.2.15是从Homebrew安装的。以root身份运行没有任何区别。我在这一点上假设这只是SDL中的一个错误,但我喜欢被证明我在这里做错了。

来源:https://github.com/mikepurvis/joystick_sdl

2 个答案:

答案 0 :(得分:1)

您需要查看以下SDL2函数调用:

SDL_GameControllerAddMappingsFromFile

这将在游戏手柄配置中读取SDL2不支持的游戏手柄。

要获得社区维护的控制器列表,请查看: gamecontrollerdb.txt

要为可能存在的模糊游戏手柄创建自己的映射,您需要运行SDL / test / controllermap.c示例。 要在OSX上构建此示例,我使用了:

$ gcc controllermap.c -lSDL2 -I ../include -o controllermap -L ~/lib/ -framework AudioUnit -framework Carbon -framework ForceFeedback -framework CoreAudio -framework CoreVideo -framework IOKit -framework Cocoa

答案 1 :(得分:0)

现在这是古老的历史,但问题是我的控制器(Logitech F710)处于XInput模式而不是DirectInput模式,通过设备顶部的开关。 Mac OS X不支持XInput。

翻转开关(至“D”)使控制器按预期工作。

比照http://cantonbecker.com/etcetera/2015/logitech-f710-for-os-x-macintosh-setup/