How to support gamepad/joystick

Member
Posts: 86
Joined: 2008.04
Post: #1
What is the best way to add support for joysticks/gamepad to a mac game...

I can't seem to find any apple sample code that demonstrates support....
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
With pain, suffering, hair-pulling, bloodied keyboard, and the HID Manager.

The HID Manager has two interfaces; the new one added in 10.5 is a bit nicer than the old, but either way, you're left on your own with respect to calibration, element naming, etc.
Quote this message in a reply
Member
Posts: 86
Joined: 2008.04
Post: #3
OSC - Is there any sample code that you know of that supports a hid usb gamepad?
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #4
You can try ddhidlib I suppose. I haven't messed with it lately, but I don't think it supports the new API so there may be issues with that.

I haven't seen the sample code show up at Apple yet, although I haven't looked recently, but George Warner has some sample code for it on his iDisk. The file you'll want to download is LeopardHID.zip

Here's a relevant technote.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #5
If you don't mind ignoring the extra bloat that SDL has in terms of useless built in graphics and sound functionality, it has a nice cross platform event system including auto calibrated joystick input. It's a very simple and low level event system, but that makes it better suited to games anyway.

While you can't get mouse and keyboard input from SDL without creating and using an SDL window, I'm pretty sure you can use joystick input separately.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 86
Joined: 2008.04
Post: #6
Thanks for the replies - I am making a sample project to demonstrate using a USB HID joystick that I will post shortly...

Quick question:

Should I process events using a registered callback from the HID manager or is it better to poll the device every frame?

Thanks for any feedback...
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #7
You can poll analog inputs like sticks, but it's safest to queue momentary input like buttons.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Advice on coding of On-Screen Controls ( Joystick and multiple buttons) Elphaba 5 2,969 Aug 10, 2009 11:02 PM
Last Post: Elphaba
  Mouse button enabler, like GamePad Companion setera 4 4,256 Apr 30, 2006 06:32 PM
Last Post: setera