Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Broken in iPadOS 16 - InputSystem.GetDevice<Keyboard>() and registeredKeyboard.onTextInput

Discussion in 'Input System' started by Ascanio1980, Sep 30, 2023.

  1. Ascanio1980


    Jun 7, 2019
    Good morning fellas,

    I am recompiling a prototype in Unity for use on an iPad Pro 1st gen that is now udpated to iPadOS 16.5.
    The project, when everything was working, was built with Unity 2020.2.1f1. I have reinstalled that version.

    All seems good, it compiles and runs. Only thing, event listeners for key strokes on a USB keyboard are not working anymore.

    Now, I am pretty sure the culprit is Apple, as usual it seems as their job is to make developers' lives miserable. Have they further restricted access to keyboard events on iOS/iPadOS? Or is there something else going on?

    I remember back in 2020 when I originally built the prototype it took me weeks to figure out how to get the iPad to listen to the keyboard. Legacy Input wouldn't work. InputSystem was the only thing that did the trick.

    Code (CSharp):
    1. // There is a delay in getting current keyboard. For OnEnable to assign event
    2.         private IEnumerator EnableTrackingKeyboardInput()
    3.         {
    4.             yield return new WaitUntil(() => InputSystem.GetDevice<Keyboard>() != null);
    6.             _registeredKeyboard = InputSystem.GetDevice<Keyboard>();
    7.             _registeredKeyboard.onTextInput -= new Action<char>(OnKeyboardInput);
    8.             _registeredKeyboard.onTextInput += new Action<char>(OnKeyboardInput);
    9.         }
    11. private void OnKeyboardInput(char c)
    12.         {
    13.             Terminal.Trace("Keyboard input: " + c, gameObject);
    14.             // Ignore inputs out of relevant range
    15.             if (!char.IsControl(c) && (c > 32))
    16.             {
    17.                 switch (c.ToString())
    18.                 {
    19.                     case "r":
    20.                         OnUp_Pressed?.Invoke(); // Fire custom "UP" input event
    21.                         SetInteractionModeRemote(); // Turn GUI to keyboard/d-pad mode
    22.                         StartTimeOutToModeNone(); // After timeout turn GUI back to idle
    23.                         break;
    24.                 }
    25.             }
    26.         }