Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Multiple Mouse Inputs

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

  1. slightlygrim

    slightlygrim

    Joined:
    Jul 10, 2017
    Posts:
    8
    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,595
    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:
    946
    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,734
    Rewired should be able to handle this. It handles everything else input related.
     
  6. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    16,211
    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:
    7,163
    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,734
    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,485
    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:
    16,211
  11. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,485
    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:
    4,373
    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:
    44
    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
unityunity