Sticky Keyboard Input, keys get stuck in down state

I just updated to the new Unity 2021.2.2.

I have been having this Sticky Keyboard input problem for ages.
This problem has actually been in several versions, I believe starting at around 2020.3.17.

This problem seems to be getting worse in this new version. Maybe because editor performance has regressed.

The problem is, when pressing down a key, sometimes Unity will not recognize that the key is lifted.

It happens more frequently when frame rate is lower. I think it’s related to the “lazy updating” the unity editor does. The stuck key gets resolved when any other key is pressed, or the mouse is moved.

I submitted a report that uses Rewired so I can’t post the project here.

Case: 1380143

1 Like

Oh. Just reproduced without Rewired.

Just using "Input.GetKey( KeyCode.W) " will cause the bug… :frowning:

Probably this is specific to macOS editor. I really wish there were more engineers at Unity using macOS, cause the usability is getting worse every version. Not to mention the invisible, blacked-out-panels in the new version of Unity.

But to be clear, I’ve been experiencing this bug since LTS 2020.3.17 on an intel mac (probably when the underlying Input changed… and caused this bug ). It’s just even worse now in 2021.2.2.

Repro steps:

  1. open SampleScene.unity
  2. tap W and S to move cube
  3. Sometimes, after tapping W or S, it will get stuck, making your cube continue moving forever.
  4. Move the mouse or hit any other key on the keyboard to “reset” the stuck input.

7648687–953611–sticky_input_bug.zip (6.46 MB)

2 Likes

Yikes. Does this occur in built apps too? Or only in the editor?

This sounds like it’s the exact same problem that affects the Windows editor. I’ve documented this issue here:
https://guavaman.com/projects/rewired/docs/KnownIssues.html#windows-editor-keyboard-keys-stuck-raw-input

It was introduced in Unity 2019.3.8.

1 Like

Actually, I re-read the OP and I think this is different than what I posted. I didn’t realize the key was getting stuck forever. I thought he said it was getting stuck temporarily. That sounds like a different problem.

Rewired uses UnityEngine.Input for keyboard and mouse input on MacOS, which is why Unity bugs in this area affect Rewired:
https://guavaman.com/projects/rewired/docs/Overview.html#tested-platforms

I’m experiencing a similar (or the same) problem on 2021.2.2f1 / 2021 14" Macbook Pro M1 Max running MacOS Monterey. Using the new Input System - version 1.1.1 - and I am not using Rewired.

Have only tested in editor, but the best way to describe it is that the input actions for movement get stuck: I occasionally will take my hands off the keyboard and the input will continue to return a non-zero value until I touch the keyboard or trackpad. There’s also often lag in the start of the same input action registering. I’m using the InputActionVisualizer to look at the action’s output directly and it’s easy to observe the lag / reproduce the stuck condition.

There was a separate input lag issue in the context of the editor on 2021.2.0 but that has been fixed.

Tried reproducing in a new project but with no success; perhaps due to very high frame rates.

Would love to know if others are experiencing this in 2021.2.2f1 on Mac silicon with the new Unity Input. Thanks!

1 Like

Still exists in new version 2021.2.3.

It makes my game really unplayable. I don’t know how to make a videogame with a faulty inconsistent inputsystem…

Using WASD to move around… frequently Unity won’t send a “key up” event and my character will continue moving in one direction forever.

I attached the repro up above, which reproduces the issue without rewired, with just 1 script that uses Input.GetKey.
It will reliably get stuck.

Still no response from devs on this? Is this a known issue at least?
Should I post on the Input forum as well? I already filed a bug (1380143)

I can repro this. Thanks for your report. We will look into it. And thanks for the repro project. That helps a ton.

It seems to only repro when frame time is very long (low FPS). Is this in line with your experience?

1 Like

I’m pretty sure this issue was already present in the 2019.x versions, assuming similar issues with and without the new InputSystem are caused by the same things. Only the editor has ever been affected.

Thanks for taking a look at this!
I think it’s related to low FPS, but it still happens on my project even when it’s running at 100+fps on M1 Max.

On the 2019.X releases I was able to “bypass” the issue by setting the editor interaction mode to 33ms (30FPS).

Sadly the same workaround isn’t working on 2021.2.3, as I think that option is broken.

I also tried setting Application.targetFrameRate = 30, which does indeed throttle the game to 30FPS, but it doesn’t help workaround this issue in my case.

In my case, I wouldn’t say frame time is particularly high (it’s a prototype, and I’m on an M1 Max, so generally things are 60hz+).

But trying to reproduce in an empty project didn’t work; frame time was miniscule and I didn’t have the time to try and introduce artificial slowdown.

This matches my experience. This bug causing sticky input makes for a miserable combo with the [Apple Silicon editor bug]( https://discussions.unity.com/t/844035 page-9#post-7681606) where the FPS drops substantially in the GameView when the SceneView is open…

I have exactly the issue you describe, with the same machine config, but I am not using the new input system at all.

Regarding the Scene / Game view perf issue, that is unfortunately a known issue and is shared between the Intel and Apple silicon editors. Resolving that issue is non-trivial.

But as far as this issue with sticky keys, I have feelers out to get to the root of the issue. The response will be delayed due to Thanksgiving and upcoming holidays in the US, but we are working to get to the bottom of it.

3 Likes

Thank you for the update, I really appreciate it. Currently my workaround is to use a gamepad, which works well enough for me to test my game in the editor.

Just another note: I noticed that the sticky key issue also happens in the Editor sometimes, even not in play-mode. It leads me to believe that it’s something that’s not associated with the Input Systems, but actually just how the Editor is ticking.

For example, sometimes using Arrow Keys to navigate the Scene View will also get stuck, even when outside of play mode. It seems to happen significantly more often in performance heavy scenes.

2021.2.4 kinda solved the lag issue but not the sticky keys sadly … keep up the good work !

I saw 2021.2.5 was released, anyone knows if the issue got resolved? Thanks in advance

This isn’t yet resolved. We are investigating what to do on our side as our investigation so far points to this at least partially being a macOS bug.

2 Likes

Also, the game view is never focusing on Mac, I have to click to focus. “Maybe” that’s related ?

Any chance it’s solved in 2021.2.6 ?