Search Unity

Multiple Mouse Inputs

Discussion in 'Editor & General Support' started by slightlygrim, May 24, 2018.

  1. slightlygrim

    slightlygrim

    Joined:
    Jul 10, 2017
    Posts:
    13
    Hi Guys

    So I've seen it done but no idea how and not much online about it (that not very old and out of date) but is it still possible to have multiple mouse inputs into unity.

    I'm trying to measure the movement of a wheel and have figured out to do it with the mouse in an accurate simple way but need to have a second input mouse to track another wheel.

    Help would be really appreciated.

    Thanks
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    I'm not aware of Unity doing this as standard (although happy to be proved wrong). The Input-mousePresent help says "Indicates if a mouse device is detected".

    Given that implies singular (or at least harmonised to one in the case of multiple), I would suggest you have 2 options:
    1. Write your own low level mouse reader (C++ / C#) and import that DLL into your solution.
    2. Try out an asset already created to do that for you, for example, this one.
     
    Joe-Censored likes this.
  3. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    You could get a raw input stream from the Windows API, but that's a problem because then you have to know exactly where the mouse is. In Linux it's a little easier as you should be able to just read pipes from ./dev/input/mice
     
  4. Refet

    Refet

    Joined:
    Nov 7, 2018
    Posts:
    1
    I need to use same mouse movements in several same program.How to do it?Anyone knows?
     
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Rewired should be able to handle this. It handles everything else input related.
     
  6. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,155
    Rewired can only handle a single keyboard and a single mouse. Multiple devices will act as a single universal device.

    http://guavaman.com/projects/rewired/docs/Controllers.html#keyboard
    http://guavaman.com/projects/rewired/docs/Controllers.html#mouse
     
  7. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,145
    Windows, MacOS, and all of Ubuntu's major window managers do not support separating mouse inputs like this iirc.
     
  8. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    That's disappointing. My stock response of "rewired" to "something something something input something" has never let me down before.
     
    gnurk, Joe-Censored and Lurking-Ninja like this.
  9. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    There is this asset. Never tried it myself.

    https://forum.unity.com/threads/multi-input-handle-many-keyboards-mice-and-pads-all-at-once.396770/
     
  10. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,155
  11. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Actually I just noticed this asset was mentioned in a link already (message #2) and I missed it entirely. I would hope that someone who is deploying this type of solution would be very comfortable writing device drivers.
     
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Unfortunately, supporting multiple mice and keyboards isn't something I ever got to implement. It would be fairly easy to do on Windows on the back end since I already have the mouse working through Raw Input (which is how you have to support multiple mice). OSX and Linux are another story. Plus, the front end would have to change a lot since the Controller Map system was designed around a single mouse and keyboard. So few people need these features it just doesn't seem worth the effort. I've had maybe 5 people ask in over 4 years.
     
    gnurk, Kiwasi and Lurking-Ninja like this.
  13. petersvp

    petersvp

    Joined:
    Dec 20, 2013
    Posts:
    63
    On Win32, there is RawInput.
    Unity compatible example AND MouseInputManager here:
    https://pastebin.com/u/PeterSvP

    You need C++ compiler (yes C++) - to compile the DLL
    (replace HWND_DESKTOP with HWND_MESSAGE to get rid of the visible window)
     
    Last edited: Aug 7, 2019
  14. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    Have you actually tried this .dll?
    How do i go about compiling it? And using it?
    Are there any step-by-step instructions?
     
  15. petersvp

    petersvp

    Joined:
    Dec 20, 2013
    Posts:
    63
    Sorry for the very late response. I wrote this DLL myself for an old game I eventually cancelled. I only released this as the C++ code. Literally create a new dll project, paste that code, build it and drop it onto unityYou can compile this using visual studio and drop the dll and the mouse input manager into your project. Given that I'm programmer, if you are a designer ask your programmer, he will know what to do. In really not providing support for this thing as it's primitive but with it you can do a lot. The provided C# example in my paste bin shows how to use the DLL itself. You need to setup a canvas with mouse pointer prefab, instantiate such prefabs and update their position based on the events you get from polling the dll. And you need to implement clicking by yourself too :)
     
    Last edited: Feb 24, 2023