Search Unity

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

Discussion in 'Input System' started by bitinn, Oct 15, 2021.

  1. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    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:



    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.

    Screen Shot 2021-10-15 at 11.15.26.png Screen Shot 2021-10-15 at 11.15.15.png Screen Shot 2021-10-15 at 11.15.09.png

    - My callback handles it like following, basically Input System never fired
    canceled
    callback as promised, not until I press another key or use touchpad.

    Code (CSharp):
    1.         public void ReadCameraFocusRotation(InputAction.CallbackContext context)
    2.         {
    3.             if (context.canceled)
    4.             {
    5.                 m_CameraFocusRotationTimeout = m_InputConfig.CameraMovementTimeout;
    6.             }
    7.             else if (context.performed)
    8.             {
    9.                 m_CameraFocusRotation = context.ReadValue<Vector2>();
    10.                 m_CameraFocusRotationTimeout = MAX_TIMEOUT_VALUE;
    11.             }
    12.         }
    13.  
    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!
     
    siliconkgk likes this.
  2. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    Case no. 1373221
     
  3. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    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.
     
  4. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    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:

     
    Deleted User likes this.
  5. Deleted User

    Deleted User

    Guest

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

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    Yep I’ve got this too.
     
  7. Rickshaw

    Rickshaw

    Joined:
    Dec 3, 2013
    Posts:
    5
    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
     

    Attached Files:

  8. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    @Rickshaw Out of interest are you on an Intel or AS Mac?
     
  9. jsm174

    jsm174

    Joined:
    Jul 22, 2015
    Posts:
    16
    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:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. public class KeyboardTest : MonoBehaviour
    5. {
    6.     public InputAction _action;
    7.  
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.         _action = new InputAction(
    12.             type: InputActionType.Button,
    13.             binding: "<Keyboard>/W");
    14.  
    15.         _action.Enable();
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.         if (_action != null)
    22.         {
    23.             if (_action.WasPressedThisFrame())
    24.             {
    25.                 Debug.Log("PRESS");
    26.             }
    27.             if (_action.WasReleasedThisFrame())
    28.             {
    29.                 Debug.Log("RELEASE");
    30.                 Debug.Log("----");
    31.             }
    32.         }
    33.     }
    34. }
    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!
     
  10. ManuelRauber

    ManuelRauber

    Joined:
    Apr 3, 2015
    Posts:
    122
    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.
     
  11. jsm174

    jsm174

    Joined:
    Jul 22, 2015
    Posts:
    16
    Last edited: Dec 13, 2021
  12. evreng

    evreng

    Joined:
    Oct 24, 2014
    Posts:
    4
    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)
     
  13. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    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.
     
  14. jsm174

    jsm174

    Joined:
    Jul 22, 2015
    Posts:
    16
  15. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961