Gamepad code on OS X: Buh? - macos

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?

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.

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...

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!

No code, but communicating with gamepads and the like is pretty straightforward with the InputSprocket mechanism. What was the precise problem you had?

Related

Making my own gamepad Driver?

I am trying to find out how I should go about making my own gamepad compatible with windows based games. I have used some time to read up on windows drivers but I feel kind of lost and unsure about how I should solve my problem. What i am asking for is some guidance toward what kind of solution or approach I should take.
So I have made a Arduino based GamePad which communicates with the computer over serialport(usb). From here I assume I need to make a driver which identifies itself as a GamePad(Device driver, Plug and Play driver)? I am not sure if I am done at this point or if I have to be compatible with DirectInput somehow?
-Michael
Forum thread about arduino and ppJoy virtual joystick.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210699098

OSX Leopard HID getting simple keyboard input example?

I am about to implement simple keyboard and mouse input on osx for my engine. I want to abstract the implementation in more generic c++ classes like Keyboard and Mouse plus appropriate Listeners for portability. Anyways, I came across the Leopard HID Api (http://developer.apple.com/mac/library/technotes/tn2007/tn2187.html#TNTAG9000-SAMPLE_CODE_)which seems to be the right way to go for the osx implementation of these classes. Anyways, the examples of the HID are very complex and I can't really wrap my head around it as fast as I wished I could, so I was wondering if anybody has used it allready to get some basic mouse and keyboard input, or knows about some good examples/resources online.
Or Maybe even a totally different way to go?
thanks

Bluetooth proximity hooks on OS X. How? (i.e., automatically lock screen if I move away)

I have a macbook pro. I would like to have my screen lock when I (my phone) moves away from the laptop. I'm sure third party solutions exist, but if I'd like to code something from scratch, what libraries or hooks should I be looking at?
http://web.mac.com/jhollington/technocrat/The_Technocrat/Entries/2007/3/18_Bluetooth_Proximity_Detection_on_OS_X.html has a pretty good step-by-step on how to do a lot of this, although it's using an existing app. That app is open source though, so maybe this will help too? http://code.google.com/p/reduxcomputing-proximity/
I know it's an old question, but I've stumbled upon it today and have an answer.
Here's an opensource third-party solution: BLEUnlock
Lock/unlock your Mac with your iPhone, Apple Watch, or any other Bluetooth LE devices
It contains a modern version of all the code you need. Plus, the app itself supports hooks so you can add a hook to the app instead of writing your own.

Simulate USB insertion on OSX via software

How can I inject USB device nodes into OSX (>= 10.5) such as you might be able for debugging USB handlers / writing new USB drivers?
I'm interested in this in order to handle non-USB devices using TokenD.
From what it looks like, I would have to tackle faking USB-device insertion and then create a PC/SC ifdHandler that would handle this fake device. (If anyone knows of any other way to inject a not-necessarily-device-backed TokenD, let me know!).
I'm guessing IOKit may be involved in this solution... as that is the underlying item I need to 'trick'.
IOKit is pretty much the only thing involved, and you'll have to get a good grip on how it works before more specific answers will make any sense. If Apple's documentation doesn't do it for you, Amit Singh's book should pick up a lot of the slack, even if it is a little bit dated.

Direct access to keyboard events in OSX

I'm looking for application-wide access to raw keyboard events in OS X, either using the Cocoa or Carbon frameworks (or any of the underlying APIs, for that matter). I know that I can override NSApplication's sendEvent: to get raw keyboard information, but for the meta keys (command, control, alternate, shift, etc) don't show up as keystroke events. I'm looking for something analogous to Microsoft's DirectInput framework.
Thanks!
I think the equivalent to DirectInput is HID Manager. HID stands for "human interface device" and HID Manager (sometimes called HIDLib) is the low-level API to HIDs: keyboards, mice, and joysticks.
Leopard's got a new HID Manager API, documented in Technical Note TN2187. The pre-Leopard API is documented in HID Class Device Interface Guide. I wrote an Objecive-C wrapper around the older APIs, DDHidLib, which you may find useful. The Leopard API is much nicer. I'd use that directly, if you can.
The Core Graphics framework also has some useful functionality buried in it as part of the remote operation system. Look for CGRemoteOperation.h, and check out the Quartz Events reference.
You can use the Quartz Events system to install application-specific or system-wide "event taps", which let you monitor and inject keyboard and mouse events at a pretty low level. A few years ago there were some bugs with application-specific event taps, but they've hopefully been worked out by now.
I think the HID stuff is mostly for driver development, so if you're just looking for a tool for your application, HID is probably overkill.
NSResponder derived classes have a method -(void)flagsChanged: that gets called when meta-keys are held down.
You can use the RegisterHotKeyEvent Carbon function, I'm not sure if you can register for any of the meta keys explicitly though.
The blog post Program Global Hotkeys in Cocoa Easily explains how to do this.

Resources