tags:

views:

1270

answers:

6

I am developing an OS X application that is supposed to take input from two mice. I want to read the motion of each mouse independently. What would be the best way to do this?

If that is not possible, is there a way to disable/enable either of the mice programmatically?

A: 

You could look at the USB/PS-2 device interrupt. Even if you don't want to rewrite a so called driver, it could be usefull since all the mice send their data through.

You could also check this page that could give some hints http://multicursor-wm.sourceforge.net/

Boris Guéry
Macs don't have PS2 today and they never had, the old connection is called ADB (Apple Desktop Bus) and it looks much more like s-video than PS2 connector wise.
Kris
i don't think stopping on this will help.The idea was to looking at more low level to have more control on devices...
Boris Guéry
+6  A: 

It looks like the HID Manager is what you're looking for.

+1  A: 

Unless you can force one of the mice to not be dealt with as a mouse, both will continue to control the pointer. However, you can use IOKit to write a custom USB HID driver to allow your app to read from one or both of the mice (although this would probably interfere with using them as normal mice). Building Customized User Client Drivers for USB Devices would be a good place to start for how to interact directly with USB mice.

One could hide the actual cursor and draw each mouse's position separately.
Lyndsey Ferguson
You can both hide the cursor and disassociate the mouse from the cursor:http://developer.apple.com/documentation/GraphicsImaging/Conceptual/QuartzDisplayServicesConceptual/Articles/MouseCursor.html
Bids
+2  A: 

You're going to want to check out the I/O Kit and HID (Human Interface Device) manager stuff.

HID manager is part of I/O Kit, so looking into there might be useful. There are two APIs for HID management, the older API is a bit more painful and then you have the new 10.5 and above API which is a bit more comfortable.

Important thing to understand is this isn't going to probably be just a quick fix, it may take some significant work to get it running. If you can assume you'll have 10.5 or better installed, using the Leopard API will definitely help.

Also; depending on how you accomplish what you're doing, may be important for you to hide the mouse cursor as it may still move a lot even if you're receiving the information from both mice. If your application grabs the screen, I'd use CoreGraphics to disable the cursor and just draw my own.

You might also consider finding a wrapper for one of these APIs, an example can be found in this question.

Travis
You can find a c++ wrapper here: http://www.wooji-juice.com/free/pyhid/
Ross
+4  A: 

The HID Class Device Interface is definitely what you need. There are basically two steps:

First you need to find the mouse devices. To do this you need to construct a matching dictionary and then search the IO Registry with it. There is some sample code here, you will need to add some additional elements to the dictionary so you just get the mice instead of the all HID devices on the system. Something like this should do the trick:

// Set up a matching dictionary to search the I/O Registry by class
// name for all HID class devices`
hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);

// Add key for device usage page - 0x01 for "Generic Desktop"
UInt32 usagePage = 0x01;
CFNumberRef usagePageRef = ::CFNumberCreate( kCFAllocatorDefault, kCFNumberLongType, &usagePage );
::CFDictionarySetValue( hidMatchDictionary, CFSTR( kIOHIDPrimaryUsagePageKey ), usagePageRef );
::CFRelease( usagePageRef );

// Add key for device usage - 0x02 for "Mouse"
UInt32 usage = 0x02;
CFNumberRef usageRef = ::CFNumberCreate( kCFAllocatorDefault, kCFNumberLongType, &usage );
::CFDictionarySetValue( hidMatchDictionary, CFSTR( kIOHIDPrimaryUsageKey ), usageRef );
::CFRelease( usageRef );

You then need to listen to the X/Y/button queues from the devices you found above. This sample code should point you in the right direction. Using the callbacks is much more efficient than polling!

The HID code looks much more complex than it is - it's made rather "wordy" by the CF stuff.

Bids
A: 

maybe it's a solution for you to use usb->rsr232 converter and go by reading the serial port by yourself ?

lImbus