用户空间中Mac OS X上的游戏手柄和操纵杆支持 [英] Gamepad and joystick support on Mac OS X in user space

查看:132
本文介绍了用户空间中Mac OS X上的游戏手柄和操纵杆支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天来,我一直在寻找如何在Mac上进行游戏手柄和操纵杆支持的工作,而我发现的所有资源似乎都暗示了预装驱动程序以及使用Apple的HID API的效果.

I have been searching through how to do gamepad and joystick support on Mac for some days and all resources that I found seems to suggest a pre-installed driver along with using Apple's HID API, which works.

这种方法的缺点是每个操纵杆和游戏手柄都需要加载另一个内核扩展,因此它可以被HID管理器识别,或者至少需要一个少于 Info.plist 的代码符合先前安装的驱动程序.例如,当我有一个360 Xbox驱动程序 KEXT在内部,可以使用Microsoft的Xbox控制器,但不能使用Logitech的Xbox控制器(我尝试过F710).

The drawback about this approach is that each joystick and gamepad will require another kernel extension to be loaded, so it can be recognized by HID manager, or at least a code less Info.plist saying it conforms to the earlier installed driver. For instance, when I have an 360 Xbox driver KEXT in house, the Xbox controller from Microsoft will work, but not the Logitech one (I tried F710).

正如苹果公司所建议的那样,使用游戏手柄或操纵杆的应用程序应该能够在用户空间发挥作用而无需引入任何KEXT东西.有办法吗?

As Apple suggests the application that uses a gamepad or joystick should be able to do themselves at user space without introducing any KEXT stuff. Is there a way to do it?

我想到的事情就像是使用IORegistry或IOUSB API在插入设备时获取设备一样(至少USB Prober会显示它).然后以某种方式获取设备的描述,然后使用该描述将设备注册为HID.然后可以使用整个HID管理器.

The thing I had in mind was something like using IORegistry or IOUSB API to get the device when they get plugged in (USB Prober shows it at least). Then somehow get the description of the device, then use that description to register the device as a HID one. Then the whole HID manager can be used.

我在正确的轨道上吗?还是有其他方法可以做到这一点?

Am I on the right track? Or is there any other way to do this?

由于IOKit API实际上提供了诸如kHIDUsage_GD_Joystick之类的关键字,并且有一个ForceFeedback.h库,因此我想苹果公司在设计HID API时就考虑了操纵杆和强制反馈.那是我抱有希望这可能行得通的渺茫希望.

Since IOKit API actually provided keywords like kHIDUsage_GD_Joystick, and there's an ForceFeedback.h library, I suppose Apple designed their HID API with joystick and force feedback in mind. That's the slim hope I had that this might work.

一些参考文档和开源项目:

Some reference documentation and open source project:

推荐答案

再次讨论之后,我发现该解决方案可以直接在设备的文件描述符上运行.libusb是一个出色的库,它极大地简化了您的工作,并且支持Mac.

After revisiting this, I found out the solution to be operating directly on the file descriptors of the device. libusb is an excellent library which greatly simplify your life on this and they have Mac supported.

xboxdrv 链接是一个很好的示例,说明了如何使用libusb在文件套接字上进行操作.

xboxdrv link is a great example on how to operate on file socket using libusb.

在伪代码中,它应如下所示:

In pseudo code, it should look like this:

  1. 枚举设备
  2. 检测内核驱动程序,并在可能的情况下将其分离
  3. 打开设备
  4. 取消初始传输的文件
  5. 等待回调函数正确处理味精和错误
  6. 开始运行循环或在fd上选择以调用libusb_event_handle

检查libusb以获得更多信息链接.

Check libusb for more info link.

这篇关于用户空间中Mac OS X上的游戏手柄和操纵杆支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆