Reputation:
I thought I was a decent programmer until I tried writing gamepad code for OS X. Now I feel deeply useless.
Does anyone know of any code that I can legally use in my (non-free) game?
Is it really this hard to talk to a gamepad on OS X? What am I missing?
Upvotes: 10
Views: 3276
Reputation: 36139
The quickest way to get gamepad events on OSX is to use SDL, the game library. You don't have to use the whole library, you can just init the joystick subsystem and then poll or wait for SDL_JOYAXISMOTION and SDL_JOYBUTTONUP/DOWN events. SDL has an LGPL license, so you can dynamically link to it in your non-free game.
Easy!
Upvotes: 2
Reputation:
Turns out the answer was Apple's HID_Utilities, which (somewhat) simplifies the job of talking to HID Manager.
John Carmack really hit the nail on the head when he said that Apple don't care about games...
Upvotes: 3
Reputation: 55164
Check out the HID Manager, especially the new HID Manager APIs in Leopard. It's somewhat verbose, but the essence of it is that you can get callbacks when devices are attached and detached, and get callbacks when events from those devices are enqueued.
If you're working with Cocoa, Dave Dribin has DDHidLib which provides a nicer Objective-C API atop the HID Manager, and runs on Tiger as well.
Upvotes: 3
Reputation: 2288
No code, but communicating with gamepads and the like is pretty straightforward with the InputSprocket mechanism. What was the precise problem you had?
Upvotes: -1