Keyboard.anyKey stops working with alt+tab if gamepad is also used.

hey there, looks like I found a bug. happens in the build, not in the editor.

  • start the game
  • alt+tab away from the game, and then alt+tab back.
  • hit a button on your gamepad.
  • notice that from now on, Keyboard.current.anyKey.wasPressedThisFrame is always false.

This is a bit painful as I’m using anyKey to swap control states. I don’t want to create a series of if statements for every key on the keyboard if I can avoid it.

1 Like

if anyone’s curious, i just bypassed the issue with this:

Keyboard k = Keyboard.current;
            if(k.anyKey.wasPressedThisFrame || k.escapeKey.wasPressedThisFrame || k.spaceKey.wasPressedThisFrame ||
                k.eKey.wasPressedThisFrame || k.tabKey.wasReleasedThisFrame || k.altKey.wasReleasedThisFrame ||
                k.enterKey.wasPressedThisFrame || k.wKey.wasPressedThisFrame || k.sKey.wasPressedThisFrame ||
                k.aKey.wasPressedThisFrame || k.dKey.wasPressedThisFrame)
            {
//set controls to keyboard.
}

it kinda sucks because it doesn’t support re-binding, but I’m not polling every damn key on the keyboard so it’s a start.

1 Like

Just ran into this exact issue. Shocked that the alt tab is why it was happening… is there really no good way around this?

The above solution didn’t work for me (assigning keyboard as local obj in script and using it)… Fortunately there are only a few places where I get input this way in my project and you can still use Mouse to proceed so it isn’t a hugely impactful bug but it is annoying.

1 Like

Glad you found the thread, sorry my “fix” didn’t work though.

good luck is about all that I can offer.