views:

179

answers:

4

I need to build a simple app that takes (click only) input from 4 USB mice connected in addition to the built-in touchpad on a notebook. My preferred operating system for this setup would be Linux.

Any idea how I might be able to discern in an application which mouse a click came from? I'm open to C programming or whatever it takes. It's a simple, one-off project, so nothing too elaborate though.

+2  A: 

Check out these links. Also, here you may find a code sample on how to deal with multiple mouse pointers in MPX.

luvieere
First link is really really out-of-date; I believe it's actually talking about using two mice to control the same pointer.
bobince
Thank you for lots of interesting information!
Carl Smotricz
+2  A: 

I'm not too sure where to start for this, but it sounds a lot to me like it'd be similar to getting multi-touch to work. Maybe start looking for multi-touch drivers for linux?

Also, luvieere's first link might be helpful.

JasonWyatt
+2  A: 

MPX is where it's at for multiple-mouse and multitouch under Linux, but you'll need to be using xorg xserver 1.7 to get the ‘proper’ version of it; this is generally taken as part of X11R7.5, which has only just come out as ‘stable’ and has not been integrated by the distros yet. (Even xorg-edgers doesn't have it, though that's where you'd keep an eye on if you're an Ubuntu-er.)

GTK+ seems to have had some work put into allowing you to detect which mouse clicked (GdkEvent.gdk_event_get_device), but I don't know what the timetable is for getting this into a full stable release. Nor do I know how far along Qt4 is with it. So in summary the situation is: it works if you're willing to put the time into grabbing, compiling and fixing stuff, but it's not smooth with mainstream Linux, yet.

bobince
Good detailed information, though it drove me to seek a simpler solution :)
Carl Smotricz
+2  A: 

For what it's worth, I think I found an answer to my question.

bobince's mention of xorg led me to look in /etc/X11/xorg.conf. That turns out to be full of comments like

# commented out by update-manager, HAL is now used

I had heard of HAL before, and not just in 2001. I tried man -k hal and found lshal, which lists 133 (!) HAL devices in my PC. In the entry for one of my mice, I found

linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:0b.0/usb2/2-7/2-7:1.0/input/input6/event6'

which turns out to be a directory in the file system. Exploring from there, I discovered a reference back to /dev/input/mouse3. In fact, all my mice were sitting there in /dev/input!

Wearing my superuser cape, I was able to read /dev/input/mouse3:

root@carl-ubuntu:/dev/input# od -t x1 -w6 mouse3
0000000 09 00 00 08 00 00
*

so it turns out a left mouse click is 09 00 00 08 00 00, consistently and repeatably.

Conclusion: I can read mouse clicks from /dev/input/mouseX. Having done chmod a+r on those files, I can even read them from a normal user account. I need to figure out a way to stop 4 mice running wild in the hands of probably drunk people from actually interacting directly with the GUI, but that's a problem for another day.

Carl Smotricz
just tell X to ignore them./dev/input/mice is an aggregator device for all mice,.... /dev/input/mouse0 is your primary mouse,so edit yuor xorg.conf and you're done
Tim Williscroft
Heh, if only I could! There are no longer any mice (in fact, any input devices) configured in xorg.conf . But I'm not really troubled by this - I made my app cover the whole screen so it doesn't matter where the pointer is.
Carl Smotricz