Read Mouse HID

Hellow,

Does anyone know if it’s possible to read mouse HID? I’ve seen documentation on how to read HID from PS4 controllers etc.
So my common sense tells me that it’s possible to read a Mouse HID. I want to read mouse HID because I have two mice connected to my computer.
I’m making a two-player game, where each player will physically sit next to each other and play the game using the separate mouse to point and shoot enemies.

1 Like

If you want to assign the mouse for a player, maybe you can use the device ID?

7414046--906824--OneMouse.png
That was a clever suggestion. Unfortunately, Unity’s Input system ignores Multiple Mouse. I currently have Two mice plugged into my computer, one keyboard, and one USB Gamepad. However, from debugging the InputSystem, it only reads one mouse.

Ah. Now that you say that iirc, multiple keyboard and mouse are not supported it seem.

https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/KnownLimitations.html

7414361--906890--upload_2021-8-13_9-43-58.png

My bad then :frowning:

1 Like

alternatives,
c++ dll

or ready asset

Thanks for the effort at least. I appreciate it.

I got the Multiple Asset from Unity Store. It works and does what it says it’s supposed to do.
However, I’m actually using a Lightgun as a Mouse in my game. I have two USB IR Lightguns, when plugged into my PC, Windows 10 recognizes them as a USB Mouse. I can move the Lightguns around just as a regular mouse for pointing and clicking.
The Multiple Asset package I purchased from the Unity store seems to have a hard time reading the X-Y of the Lightguns.

For the C++ .dll.
Do you know how that’s supposed to work. I read the thread and downloaded the C++ code and tried compiling it but I don’t understand how it’s supposed to be used. The owner doesn’t have much documentation.

i think it should produce dll when compiled, then place dll to your project (in Plugins/ and or project root if dll not found), and c# script calls the dll.

I spent much of the day and I finally figured it out using the Asset you recommended. I had to do a lot of hacking and debugging.

I was able to get both Lightguns to show up and read independently.

7418828--907694--thumbnail.jpg

1 Like

1 Like

Well done!
Can you send your code to help us understand how it works? :slight_smile:

Thanks for your recommendation.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using RavingBots.MultiInput; // Purchase the MultiInput Asset from Unity Asset store
using UnityEngine.Events;
using System.Linq;
using UnityEngine.UI;

public class DisplayMultipleLightGuns
{
    // InputeState class is available when you purchase the MultiInput asset from Unity Asset store.
    // Create an empty gameobject in the editor and attach a MultiInput.cs to the empty gameobject
    // Attache the empty gameobject here.
    public InputeState InputManager;

    public IDevice Gun1, Gun2;
    private IVirtualAxis Gun1InfraredXValue, Gun1InfraredYValue, Gun2InfraredXValue, Gun2InfraredYValue;

    void Start()
    {
        if(InputManager.devices.Count() > 0)
        {
            foreach(IDevice thisDevice in InputManager.Devices)
            {
                if(thisDevice.ProductID == abc123) // To get the actual product ID, you should use Windows Device Manager.
                {
                    Gun1 = thisDevice;
                }
                if(thisDevice.ProductID == xyz123)
                {
                     Gun2 = thisDevice;
                }
            }
        }
    }

    void Update()
    {
        if(Gun1 != null)
        {
            Gun1InfraredXValue = Gun1[InputCode.MouseX];
            Gun1InfraredYValue = Gun1[InputCode.MouseY];
        }

        if(Gun2 != null)
        {
            Gun2InfraredXValue = Gun2[InputCode.MouseX];
            Gun2InfraredYValue = Gun2[InputCode.MouseY];
        }

        // From here on you can do whatever you want with Gun1InfraredX/YValue and Gun2InfraredX/YValue
        // such as move cursors, laser, gameobjects etc.

    }

}
1 Like

How do you get the positional values in sync with the actual pointer device? The input value of x and y are relative, so you can add those to a previous position to get your current position. However, they start at 0 no matter where the actual mouse is on screen, so the position is always off.