Keyboard input falsely detected on Controller input

Hello,

I need to detect the last input device to show correct button hints in the ui. I’ve created an InputAction which contains all keyboard, Mouse and Controller keys like here:

But every time I press an input on the controller, before the correct controller input is detected, a keyboard input is fired right before it.

Code:

using UnityEngine;
using UnityEngine.InputSystem;

public class Test : MonoBehaviour
{
    [SerializeField] private InputActionAsset _inputActionAsset;
    private InputAction _anyKeyAction;
    
    private void OnEnable()
    {
        _anyKeyAction = _inputActionAsset.FindAction("AnyKey");
        _anyKeyAction.performed += OnAnyButtonPressed;
        _anyKeyAction.Enable();
    }

    private void OnDisable()
    {
        _anyKeyAction.performed -= OnAnyButtonPressed;
    }
    
    private void OnAnyButtonPressed(InputAction.CallbackContext obj)
    {
        Debug.LogError("control: " + obj.control);
    }
}

When I press e.g. Dpad down on the controller I get this in the log:
control: Key:/Keyboard/downArrow
control: Dpad:/XInputControllerWindows/dpad

I have the latest LTS version 2022.3.55f1 and the latest input system package for this verison: 1.11.2
I created a new scene for this where only this script is running on a GameObject

Does somebody have similar issues?
Thanks in advance!

You don’t need to make a massive input action for this. There’s a built in callback for any button press: Class InputSystem | Input System | 1.11.2

1 Like

:exploding_head:

Woah that’s not how you determine “last used device”. :wink:
There is an InputDevice class and you can enumerate those. I believe there is either a timestamp that you can compare or even a “last used” bool. Check the script reference for InputDevice and there’s I think a static method (in InputSystem?) through which you get all currently active and “lost” devices. From the top of my head otherwise I’d have actual methods to share.

1 Like

Thank you @spiney199 I will have your solution as a backup, it does not detext stick input but the bug does not persist there.

@CodeSmile I agree, this is a bad, head through the wall solution but as I had this bug before, this fixed it and now it reappeared somehow -.-

Also my solution is working again after a restart, with no keyboard input before controller input. I will try to reproduce this and keep your solutions in mind.

Much appreciated :slight_smile:

If you are able to consistently reproduce the issue, could you please submit a bug from within the Unity Editor by selecting “Help → Report a Bug…” and attach a reproduction project? If you could also tell me the ticket ID after submitting, that’d be great.

We are currently investigating the problem but have not been able to get a reproduction internally.

Hey, I’ve finally found the problem here, it is steam. When steam is running in the background and Unity Editor is running then strange things are happening to the input. This is also true when running a build, not connected to steam. Running a build from steam, which was uploaded to steamworks works fine.

Should I still create a bugreport for this? Can you do something here?

Yes, go ahead and send a bug report. Then we’ll check it out and see if it’s an issue on our end