In PlayerInput, Switching Control Scheme fails with OnAnyButtonPressed for keyboard input

If I switch control scheme directly like this, the PlayerInput update correctly :

playerInput.SwitchCurrentControlScheme(Keyboard.current, Mouse.current);

But if I listen to InputSystem.onAnyButtonPress to get the InputDevice with a keyboard device, the PlayerInput doesn’t change its device and control scheme:

 OnAnyButtonPressed += device =>
{   
     playerInput.SwitchCurrentControlScheme(device);
}

Listening for multiple different Gamepads with OnAnyButtonPressed will correctly update the PlayerInput. But here, when the event comes from a keyboard, it doesn’t update and the PlayerInput stays at its last devices and control schemes . Why is it the case?

Thank you for any help!

I still don’t know why it doesn’t work. For now I literaly need to check the device name and switch the current control scheme like this to make keyboard control work :

OnAnyButtonPressed += device =>
{
       if (device.name is "Keyboard" or "Mouse")
       {
            playerInput.SwitchCurrentControlScheme(Keyboard.current, Mouse.current);
       }
       else
       {     
            playerInput.SwitchCurrentControlScheme(device);
       }
}

For example, this just make the device disappear, when it’s a keyboard, but it works correctly for gamepads :

OnAnyButtonPressed += device =>
{
      playerInput.user.UnpairDevices();
      playerInput.SwitchCurrentControlScheme(device);
}

Result for Keyboard :

image

Result for Gamepad:

image