Search Unity

How to detect the keyboard and the mouse "as the same input device"?

Discussion in 'Input System' started by gillemp, Apr 22, 2020.

  1. gillemp

    gillemp

    Joined:
    Nov 23, 2015
    Posts:
    78
    Hello,

    I'm trying to use the PlayerInputManager of the new InputSystem (preview 7) and my keyboard and mouse are being detected as separate devices. I'm not saying that it is wrong, but it is not useful at all and I would like to know how to fix it.

    As shown in this video, the PlayerInputManager has the ability of Instantiating new players when they press a button of their controller. This is almost exactly what I need, but it is not perfect.

    All works fine using controllers but if someone wants to join using the keyboard/mouse, "they won't be able".

    When a key is pressed in the keyboard, a player joins, and when the mouse is used, another player joins (despite the fact that in that game youn need both to control a character and neither one of the spawned characters would be playable).

    So my question is: how can I configure the InputSystem so that only one player joins when either a keyboard or mouse is used and it reads the input from both devices?

    Maybe it is simply a missing feature, but I think that it would be nice if you could achieve what I want because a lot of times the keyboard is used alongside a mouse.

    Thanks in advance!
     
  2. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,689
    For this to work, you'll need to use control schemes. Without control schemes, PlayerInput won't know which devices go together.

    Use the button in the top left corner to add control schemes.

    upload_2020-4-22_19-26-35.png

    In the popup, add both a keyboard and mouse for the keyboard&mouse control scheme.

    upload_2020-4-22_19-27-26.png

    Use the control scheme matrix in the bindings properties pane to associate existing bindings with control schemes.

    upload_2020-4-22_19-28-20.png
     
    CashMonkey, Zelgadis87 and gillemp like this.
  3. gillemp

    gillemp

    Joined:
    Nov 23, 2015
    Posts:
    78
    Thanks a lot!!!!

    I'm just starting to work with this new system. I'm loving it, great job!
     
  4. mjcguada

    mjcguada

    Joined:
    Jan 31, 2016
    Posts:
    2
    Hi, I find myself on the same problem as Gillemp, so I've just created my control schemes and now the game doesn't notice when I press any button :( neither gamepad nor keyboard&Mouse. If I set the default control scheme it works but I need it to work in the "any" option
     
  5. mjcguada

    mjcguada

    Joined:
    Jan 31, 2016
    Posts:
    2
    I've been debugging the code and discovered that the PlayerInput object's attribute hasMissingRequiredDevices is false before assignation and true after, the code:
    upload_2020-9-12_21-44-0.png
     
  6. Owlbear_Headspin

    Owlbear_Headspin

    Joined:
    Jun 25, 2016
    Posts:
    4
    Setting the control scheme is easy enough, but I still don't know how to detect it in the code.
     
  7. Ommageden

    Ommageden

    Joined:
    Sep 24, 2020
    Posts:
    7
    I'm also wondering how to detect it via code
     
unityunity