Search Unity

How to bind Keyboard AND mouse to a user?

Discussion in 'Input System' started by benthroop, Jun 7, 2021.

  1. benthroop

    benthroop

    Joined:
    Jan 5, 2007
    Posts:
    263
    I have the following code:

    Code (CSharp):
    1.                
    2. var keyboard = Keyboard.current;
    3. var mouse = Mouse.current;
    4. user = InputUser.PerformPairingWithDevice(keyboard);
    5. user = InputUser.PerformPairingWithDevice(mouse);
    6. user.AssociateActionsWithUser(myInputActionsAsset);
    The result is that the user is only paired with the mouse. I am not clear on how to pair the user with two devices at once. Can someone advise?
     
  2. Munkey

    Munkey

    Joined:
    Oct 26, 2013
    Posts:
    23
    This is exactly what I'm trying to find out, anyone? OP?
     
  3. the_unity_saga

    the_unity_saga

    Joined:
    Sep 17, 2016
    Posts:
    273
    did anyone figure out a solution to this?
     
  4. Munkey

    Munkey

    Joined:
    Oct 26, 2013
    Posts:
    23
    Finally found the answer in a random post. This REALLY needs to be added to the documentation as it is absolutely not intuitive.

    To bind both the Mouse and Keyboard to a InputUser you must do the following:

    Code (CSharp):
    1. var User = InputUser.PerformPairingWithDevice(Keyboard.current);
    2. InputUser.PerformPairingWithDevice(Mouse.current, user: User);
    This was found by digging through @Rene-Damm 's posts looking for an answer to this until stumbling upon this post: https://forum.unity.com/threads/sol...e-player-input-component.856108/#post-5669128
     
    the_unity_saga likes this.