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:
    81
    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!
     
    coatline likes this.
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    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
     
  3. gillemp

    gillemp

    Joined:
    Nov 23, 2015
    Posts:
    81
    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:
    6
    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
     
  8. suffron

    suffron

    Joined:
    Apr 5, 2021
    Posts:
    5
    I just came to this problem - mouse and keyboard separate I typed out the control schemes but now it doesn't register button being pressed on player manager
     
  9. pertusin

    pertusin

    Joined:
    Sep 4, 2020
    Posts:
    1
    After setting the control schemes set Join Behaviour in Player Input Maganer to "Join Players When Action Is Triggered" then create Action in your Input Actions (i called it Join) and set up Any Key for keyboard and start for gamepads. Set Join Action to Use Reference and assign "Join" reference. Worked for me!

    May be helpful for other people who stuck with same problem.