Platform inconsistency: keyboard events on macOS doesn't fire as expected

Hi,

I was making a prototype with input system v1.1.1 on Unity 2021.2.0f11 beta, and ran into this problem that I am unsure if Input System is the culprit or not.

What I observe is that event TEXT on macOS is sometimes not followed by a STAT event, and the high-level Input System consider the key is never released, so the Control value remain at 1 forever.

Here is a simple repro video:

jshx90

Notice the control for “r” key remain at 1, even when my hands are off keyboard; it only fires STAT event when I interaction with the touchpad (and I didn’t touch the keyboard).

Notes:

  • I was able to reproduce this on both my MBP 2020 and MBP 2015, both with macOS Catalina; but I was unable to reproduce it on a Windows machine.

  • I wasn’t reading these events myself, I was using the high level API, through Player Input and its Unity Events.

  • My setup for the action is like this, which I believe is fairly normal.

  • My callback handles it like following, basically Input System never fired canceled callback as promised, not until I press another key or use touchpad.
        public void ReadCameraFocusRotation(InputAction.CallbackContext context)
        {
            if (context.canceled)
            {
                m_CameraFocusRotationTimeout = m_InputConfig.CameraMovementTimeout;
            }
            else if (context.performed)
            {
                m_CameraFocusRotation = context.ReadValue<Vector2>();
                m_CameraFocusRotationTimeout = MAX_TIMEOUT_VALUE;
            }
        }

I cannot upload my code due to various factors, but I believe I have given enough information for a repro.

Please help to look into it, thx!

1 Like

Case no. 1373221

Receive no reply so far, I am guessing unless someone use the latest beta and spend their time to provide a full repro project upload, this case won’t get solved.

I now have a very minimum repro on 2021.2.0f16, the latest beta at the moment.

And I have reported it via a new case number 1374168, along with my repro sample.

This is as much as I can do for this case:

hfvfwj

1 Like

Seeing this too. Beta12 and 2021.2.3. MacOS (M1) don’t know if this matters.

Yep I’ve got this too.

I have this exact issue. I see a keyboard button down TEXT, not followed by a key-up STAT until some other input happens. It’s pretty easy to reproduce by simply starting play mode and tapping left/right repeatedly. Attached find a screenshot from the input system debugger, where I have circled a STAT that follows more than 5 seconds after TEXT, achieved by simply tapping the keyboard.

It doesn’t always happen, it is intermittent / random, feels like an update slipping in between frames or something.

I’m running Mac OS monterey 12.0.1
Unity:
2021.2.0b16.3733 Personal
Revision: 2021.2/staging edbc0738c91b
Built: Fri, 08 Oct 2021 00:41:40 GMT

Input keyboard:
Keyboard / FastKeyboard / OSX

@Rickshaw Out of interest are you on an Intel or AS Mac?

We have this same exact issue.

It happens on Intel and M1 and on 2021.2 and the new 2022.1.

We noticed we would get ActionStarted and ActionPerformed. But sometimes ActionCanceled will not occur until you move the mouse or press another key.

I tried a few other approaches and even wrote a simple test:

using UnityEngine;
using UnityEngine.InputSystem;

public class KeyboardTest : MonoBehaviour
{
    public InputAction _action;

    // Start is called before the first frame update
    void Start()
    {
        _action = new InputAction(
            type: InputActionType.Button,
            binding: "<Keyboard>/W");

        _action.Enable();
    }

    // Update is called once per frame
    void Update()
    {
        if (_action != null)
        {
            if (_action.WasPressedThisFrame())
            {
                Debug.Log("PRESS");
            }
            if (_action.WasReleasedThisFrame())
            {
                Debug.Log("RELEASE");
                Debug.Log("----");
            }
        }
    }
}

Keep pressing W, and occasionally you won’t get RELEASE.

We are building a pinball engine, and this is definitely a huge issue as it causes our flippers to stay up!

That’s odd, but using an ActionType Button here is the wrong thing.

According to the documentation, a Button is a “fire-and-forget” action (https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Actions.html#action-types), so there is no state like Action started, performed, cancelled, etc.

If you want to know when a Button has been pressed and released, you either use ActionType value or passthrough. In your example, if you switch to ActionType.Value it should work as expected.

Long time ago, I opened an issue regarding this and it’s by design. Unfortunately, most people understand “Button” as a different concept than Unity’s implementation.

@ManuelRauber ,

I believe you’re looking at the old documentation.

https://docs.unity3d.com/Packages/com.unity.inputsystem@1.2/manual/Actions.html

Regardless, the video from @bitinn , is exactly what I’m seeing too:

Edit:

Also, you can just open

Window → Analysis → Input Debugger → Devices → Keyboard

and keep pressing any arbitrary key, and eventually it will stick

I also have the same problem. This problem started after I updated my project to Unity 2021.2.7f1 from Unity 2020

macOS Catalina v10.15.7
Unity 2021.2.7f1
Magic Keyboard with Numeric Keypad (bluetooth)

Just FYI: I haven’t received any replies from Unity QA since.

Hi @Tautvydas-Zilys if you got a moment, could you try to look into it again?

Case 1373221 has been closed without reply, Case 1374168 haven’t received any update.

I think this post is the same issue:

3 months later QA replies and say “actually, we already knew about this”, and link me towards this issue:

(which was reported in Nov. when my report was filed in Oct.)

And AFAIK, Unity dev quite literally just got their fix in review status today…