Happy New Year Programmers!
Imagine a two player Java Swing game running on a computer with two mice. Is it possible to allocate one mouse per player and lock out each mouse in turn then swap the active mouse over? Both mice would share the same MouseListener methods.
I can see no internet reference to such possibilities but I feel that this situation has been visited before.
georgeFK
The issue is the device handling at the underlying OS layer. Most systems merge the inputs into a single virtual mouse, which is why you can have a trackpad and a USB mouse active at the same time. Of course when you try to use both it leads to conflicts in the pointer movement.
I think the way you would implement this would be through a native method that would talk directly to one specific mouse device. So you would use two of these objects to poll each of the mice and control the on screen game controls.
It is possible but of course not in pure Java and thus you would have to use some JNI.
Check out ManyMouse.
ManyMouse is a library that abstracts the handling of multiple mice input into a tiny, cross-platform API. It is meant to be used with games and non-traditional applications with unique input needs. On most platforms, it can at least make all USB mice available, but in many cases can make serial mice and built-in laptop trackpads available too.
Here is the source code and everything as its not available on actual website for some or other reason:
http://hg.icculus.org/icculus/manymouse/file/b9b3d0efe3c8/
http://hg.icculus.org/icculus/manymouse/file/b9b3d0efe3c8/contrib/java (the java stuff)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With