Bug with two keyboard keys pressed or released simultaneously

When 2 keyboard keys are pressed or released simultaneously one of the 2 events is not registered.

  1. The bug seems to be happening only with the keyboard. Not exactly 100% sure on this but it seem so far.
  2. It can happen with 2 directions in a WASD composite action or across 2 separate input actions that are tied to 2 separate keys.

The easiest way I found to reproduce is to make a composite WASD action:

Cache the Vector2 of that action in a Monobehaviour and track it:

using UnityEngine;
using UnityEngine.InputSystem;

public class TestNewIS : MonoBehaviour
{
    private static InputSystemMaps inputSystemMaps = default;
    [SerializeField] Vector2 input = default;

    private void Awake()
    {
        inputSystemMaps = new InputSystemMaps();
    }

    void OnEnable()
    {
        InputAction inputAction = inputSystemMaps.PlayerCharacter.MainAxes;
        inputAction.started += UpdateInput;
        inputAction.performed += UpdateInput;
        inputAction.canceled += UpdateInput;
        inputSystemMaps.Enable();
    }

    private void OnDisable()
    {
        InputAction inputAction = inputSystemMaps.PlayerCharacter.MainAxes;
        inputAction.started -= UpdateInput;
        inputAction.performed -= UpdateInput;
        inputAction.canceled -= UpdateInput;
    }

    private void UpdateInput(InputAction.CallbackContext ctx)
    {
        this.input = ctx.ReadValue<Vector2>();
    }
}

Hold both directions (in this case A and D) and try to release them simultaneously. Do this several times until you manage to pull it off and you will see that after both keys are released the cached input Vector2 will become -1,0 or 1,0. Then if you press any key on the keyboard the input will be updated to its correct 0,0 value.

Same can be tested on pressing left/A and right/D but I find it harder to time simultaneous press. In that case again the input vector will remain non-updated at 1,0 or -1,0 until some key is pressed or released (and its correct 0,0 value appears).

The same can be seen with 2 separate actions when you press and hold their keys - say left/A and some other action say Jump/Ctrl. I haven’t tried this enough but it seems that one keys is correctly considered held down while the other is only briefly detected.

5 Likes

+1 on this issue

github.com/Unity-Technologies/InputSystem/issues/663

Link to issue thread on the github repo

3 Likes

Related github issues:
https://github.com/Unity-Technologies/InputSystem/issues/663
https://github.com/Unity-Technologies/InputSystem/issues/677

Related issues in unity issue tracker:

Other post on unity forums:

Issue tracker says its fixed but I can also confirm that the issue still isn’t fixed.
It also mentions that it can’t be replicated on package version 0.2.x, also not the case.

1 Like

[TL;DR] I duplicate my post on the github here, if anyone has a workaround of this bug, i’m taking it. As my game (rhythm game) needs rapid multiple inputs on keyboard, this issue is happening a lot for me.
I need to know when a key are pressed, and when it’s released. So if someone can show me a way to configure my input actions to get the exact same result but avoiding this bug for now, I’m all ear.
Thanks a lot !


Hey, I have the same issue. My configuration is a bit different tho and I can add more details to what happen and how to reproduce.
I’m making a Rhythm Game, and this issue is happening often when I pressed 2 buttons at the same time and release it very quickly.

I have set all my button this way, for one button, two actions liked :

  • One action set at “Pass Through” for action type and “Any” for Control Type, interaction is “Press”, and the trigger behavior is “Press Only”.
  • One action set at “Pass Through” for action type and “Any” for Control Type, interaction is “Press” and the trigger behavior is “Release Only”.

Default Press point, tap time, slow tap time, hold etc… are set to zero. The update mode is set to Manual, and i’ve set it into the dynamic update look, for testing.

This way I have two actions for one button, one focused on Press only, and the other one to Release only, in separated events (I want it that way).

The problem happens when I pressed on the same frame 2 buttons and release the two button at the same time very quickly, likely the frame after. Check the debug log :

You can see on the log that I press down and left on the same frame, so the pressed action is performed, then immediatly after, the release action is started for both keys. I release the both key at the same after, and then, you can see that only the down button has the “performed” state on the release action

I managed to make the action re-appearing by unfocusing the editor window, and focusing it again, and voilĂ  :

The action is performed “a bit late”.

For me this happen often because players often quickly smash buttons on the keyboard and I got this issue every 10 secondes on every song I play.
If anyone has a workaround, I’m taking it too :slight_smile:

Thanks !

Update on the bug :

I tried with different configuration :

First, I set only on action to “PressAndRelease” instead of two actions “Press Only” and “Release only” => The bug still occurs, one of the two buttons doesn’t do both of “started/performed” state of the release action.

Then, I set my two actions to “Button” instead of “Pass Through” for “Press Only” and “Release Only” => The bug still occurs, exactly same behavior than with “Pass Through”, release action is “started” but doesn’t “perform” until you lose and get focus of the game window again.

Thanks !

Update on the bug :

I don’t know if it’s related but it seems, happening the same way, when I press two keyboard touch on the same frame.

What I do is : To prevents the issue happening, I plug the legacy input system (with GetKeyDown and GetKeyUp) on the same keys, and check if there’s an event by the legacy system before a new input system event, I trigger a warning and do the event at “Time.realtimeSinceStartup” time.

Here’s a debug log of a press that failed :

As you can see, I pressed the down and left arrow of the keyboard on frame timed [127,8916]. However, the legacy system triggers before the new input system, that only detect that the touch is pressed on frame [127, 9383].
Frame is not a problem as the input event can be processed in the next frame if they didn’t make it for this frame, I’m totally ok with that because we now have a timestamp that tells when exactly the key has been pressed.

But now check at the time I logged for the event : The legacy input system is logged at Time.RealtimeSinceStartup = 131,6768, but the new input system returns a context time of 131.7173, which is 40ms late.

So if I read the datas, it means that the new input system only catch the Left pressed event at least 40ms after the legacy system. Which is supposed to never happen with the new system.
Because if I understand correctly, the old legacy system simply says at a given frame “hey, there was an input that frame”, so the new input system should display only a value of realtimeSinceStartup inferior or equals of the value logged in an update by a legacy system call.

Which is not the case here.

So I wanted to check if it’s happening only by pressing 2 keys or if it’s does the same for one push.

I pushed 2 keys at the same time 200 times in a row, very quickly. Here’s the result :

  • I got a total of 54 warning (so 25% of press), which means the legacy input system has detected an input that is not in the correct state.
  • ~30% was due to the bug describe on this post (New input system triggering a press event later than the legacy system)
  • ~70% was due to the bug described on the previous post (New input system fails to performed the “release” state)

I pushed one key 200 times in a row, no warnings.
I pushed very quickly 4 keys one by one around 200 time each (like if you write something on keyboard), only 7 warnings (and after checking the values, it happens when 2 inputs event are really close/on the same frame, so we fall again in my first test case in my opinion), but still, can happen.

I tested it on Manual Update, Dynamic update, and Fixed updated.

The first two was given the same result, fixed update makes it worse : There’s many much event that have a timestamp later than what we can catch with the legacy system.

Conclusion : I don’t know if I setup my inputs bad, of if there’s an issue, but imho, this is weird (especially the part were the input system react after the legacy system).
If it’s an issue, I hope these informations will help you to catch the monster.
If it’s a keyboard-chair interface problem, I will be very happy if someone tell me what’s wrong.

Thanks a lot and have a great day ! :slight_smile:

The other way to “force” the missing event is to press or release any key on the keyboard.

Hey @BenouKat , any chance I can get my hands on the project you’re testing this with? Or the test files here? Would love to give this a try. Would be great if you could either upload it through the Unity bug reporter and DM me the case number or just send a zip to rene AT unity3d.com.

RE timestamps, I have suspicions that something may be going wrong with our timestamp conversion. The input timestamps we keep internally are sync’d to the engine’s internal realTimeSinceStartup, which may differ slightly from Time.realTimeSinceStartup in the player and may differ greatly from it in the editor (where Time.realTimeSinceStartup is reset every time you go into play mode). We convert to Time.realTimeSinceStartup on the fly and could be there’s actually something not quite right here.

Yep, if you push any key after the problem, the event appears, but the timestamp is still wrong.
For exemple if you have the problem, un focus and focus the window again after let’s says 5 seconds, the timestamp will be 5 seconds late.
So if you push any key, the event triggers but the timestamp is the same as the timestamp of the event of the key pushed to “unlock” the situation.

Hey Rene, sure, i’m going to send you a short project with my actual configurations, test scene and logs. I’ll send you that today ! :slight_smile:

Regarding Timestamp, honestly i’ve hit play/stop a terrible amount of time testing, and, aside from the issue we are talking above, I’ve never noticed a large problem of offsync with the Time.realTimeSinceStartup value (it works so great thanks to your team), so not sure I can help more on this subject :(.

1 Like

Hello ! Are there any news/workarounds about this issue ? I am experiencing the same problem with the 1.0.0 version of the package : my character keeps running if a release two keys at the same time. This keys don’t have to be mapped to the same action (or even don’t need to be mapped at all : if a release “right” and the “T” button, which is not mapped, the character keeps running right)

1 Like

I’m also being affected by this - looking forward to a resolution (and also glad it’s not just me! ha)

There was a bug report on a related case (which involved having two different composite bindings on one action), which was fixed in FIX: Composite bindings with the default interaction will now correct… by jechter · Pull Request #753 · Unity-Technologies/InputSystem · GitHub. I’m afraid that if some folks are still seeing this in 1.0, then there must be something slightly different about these cases, so it would be good to get a repro project for that. @BenouKat , did you ever get around to submitting that project? Or did anyone else?

I’ve just tested and the issue can still very easily be reproduced with the SimpleDemo project that comes with the package. I’ve mentioned it before

here:
https://issuetracker.unity3d.com/issues/callbackcontext-is-not-called-when-two-buttons-are-pressed-or-released?_ga=2.69684118.708210337.1569437067-675863237.1557264904

and here:
https://github.com/Unity-Technologies/InputSystem/issues/663

On the github issue I posted a short video on July 16th show casing an easy way to reproduce the issue https://imgur.com/a/GUBrWRg (video is of 0.9.2 but issue is the same in 1.0)

That bug has been fixed in 0.9.1. I have just retested it - it no longer reproduces in 1.0 (it does still easily reproduce in 0.9). So if you are still seeing an issue it must be separate from that and require different repro steps. I also cannot reproduce this in the SimpleDemo by pressing and releasing A and D at the same time. Do you have any gamepads connected when this happens (that results in different code paths being taken for deciding which device drives the action).

It’s strange, I still have this issue in 1.0.
I don’t have any gamepads connected when that happens.

If it can help, this specific bug works with keys that are not even mapped to an action. For exemple, if I hold “D” to go right and “L”, which is useless and not mapped to any action, and release them at the same time, my character will go right continuously

Any update on this? We still have the same issue in 1.0.0 preview.3

@Rene-Damm Confirmed the issue here: https://github.com/Unity-Technologies/InputSystem/issues/663
And you can follow the progress on the Unity issue tracker here: https://issuetracker.unity3d.com/issues/inputsystem-windows-simultaneous-key-presses-can-get-lost

I was experiencing this and a friend of mine was not having the same problem. We compared our work and the only difference seemed to be the version of Unity. I was on 2019.1.2f1 and he was on 2019.2.17f1. After I upgraded my version the problem went away.

I had problem with 2-buttons at once on Vector 2. I decided to create a separate action for MoveVertical and MoveHorizontal. Then the two button press worked fine.