不幸的是,除了使用 api 之外别无他法HID Manager
。不支持在 OS X 中对 HID 设备的原始访问。
文档清楚地表明:
HID family. Through the HID Manager, the HID family provides a device
interface for accessing a variety of devices, including joysticks and other
game devices, audio devices, non-Apple displays, and UPS (uninterruptible
power supply) devices.
通过 POSIX api 进行原始访问,仅适用于存储、网络和串行设备:
Using POSIX APIs
For each storage, network, and serial device the I/O Kit dynamically
creates a device file in the file system’s /dev directory when it discovers
a device and finds a driver for it, either at system startup or as part of
its ongoing matching process. If your device driver is a member of the I/O
Kit’s Storage, Network, or Serial families, then your clients can access your
driver’s services by using POSIX I/O routines.
因此,您可以HID Manager
直接使用 apis,也可以使用libusb或(如其他答案所述)hidapi,它们只不过是HID Manager
apis 上的包装库。使用这些库的好处是它们抽象了大多数低级调用,从而使它们更易于使用。