This is a CocoaPod which provides a simple API for you to work with Xbox input devices such as controllers, guitars, and drumsets.
- You need at least Mountain Lion
- Install the driver which allows you to connect Xbox input devices (Controllers, Guitars, Drumsets) to your Mac.
You're ready to roll with USB-cable devices! If you plan on using wireless devices, you'll have to buy one of those first:
Head over to cocoapods.org to learn more about how it works. Here's a quickie:
git clone git://github.com/halo/Xbox360ControllerManager.git ~/some/where
source :rubygems
gem 'cocoapods'
platform :osx
xcodeproj 'YourProject'
pod 'Xbox360ControllerManager', '0.0.1', :local => '~/some/where'
gem install bundle
bundle install
pod install
This would be a minimal implementation of your Application Delegate:
#import "AppDelegate.h"
#import "Xbox360Controller.h"
#import "Xbox360ControllerManager.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Start listening for device activity
[Xbox360ControllerManager sharedInstance];
// Register to the notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerAdded:) name:Xbox360ControllerAddedNotification object:NULL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerRemoved:) name:Xbox360ControllerRemovedNotification object:NULL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerActivity:) name:Xbox360ControllerActivityNotification object:NULL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerUpdated:) name:Xbox360ControllerUpdatedNotification object:NULL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerAction:) name:Xbox360ControllerActionNotification object:NULL];
}
- (void) controllerAdded:(NSNotification*)notification {
NSLog(@"You added a controller: %@", [notification object]);
}
- (void) controllerRemoved:(NSNotification*)notification {
NSLog(@"You removed a controller: %@", [notification object]);
}
- (void) controllerActivity:(NSNotification*)notification {
NSLog(@"You pressed some buttons: %@", [notification object]);
}
- (void) controllerUpdated:(NSNotification*)notification {
Xbox360Controller *controller = [notification object];
NSLog(@"Controller updated: %d", controller.leftStickHorizontal);
}
- (void) controllerAction:(NSNotification*)notification {
NSLog(@"Controller action: %@", [notification object]);
}
@end
If you are a little more low-level adventurous, you can also register to the Xbox360HIDAddedNotification
, Xbox360HIDRemovedNotification
, and Xbox360HIDActivityNotification
after calling [Xbox360HIDManager sharedInstance]
. Those will provide you with a IOHIDDeviceRef
on activity.
- Colin Munro is the genius behind the Mac OS driver routine.
- Derek van Vliet had an inspiring project that had the same conceptual idea behind it - and the project name :)
MIT 2013 funkensturm. See MIT-LICENSE.