How to check if a mouse is present in a mouse and keyboard control scheme

Hello,

I have recently switched over to the new input system and I have set up a control scheme that has a required keyboard, and an optional mouse. Is there some way to check if that optional device is connected or not, because I would like some functions handled by the mouse if plugged in, but revert to some buttons if it is not. Is there a good way of handling this? Would I have to create one control scheme with a required mouse and required keyboard, and one with just a required keyboard, and then check which one was active?

Thank you

I had a similar issue, and in general this looks like what we were looking for: Unity - Scripting API: Input.mousePresent

However, it looks like the behavior varies per-platform:

With PlayerInput.

GetComponent<PlayerInput>().GetDevice<Mouse>(); // Null if there is none.

Best used from OnControlsChanged.

void OnControlsChanged()
{
    var haveMouse = GetComponent<PlayerInput>().GetDevice<Mouse>() != null;
}