Mouse and Keyboard support for iOS

Is mouse and keyboard supported with the Input System for iOS/iPadOS 13+?

If not, why not?

Unity input system does not support keyboard and Mouse functionality in input system.
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/SupportedDevices.html
You have to make a native plugin with wrapper using GCKeyboard and GCMouse (just introduced in IOS 14) which will callback to unity code as all the native ads plugin wrappers does.
I think unity should update the input system as iOS 14 supports Keyboard and Mouse.
The only issue I am facing now to lock the pointer inside unity Game.


Hi, from this and your other posts I'm getting the impression that you've written a native wrapper for GCKeyboard. Would you be able to share it or sell on Asset Store for example?

I’m also interested for this :slight_smile:
It’s sad that Unity does not handle this.
I get keyboard events but I need to let the key rest by something like 0.5s between each stroke.
But i’m mostly interested by the mouse support.

Keyboard on iOS works acceptable last time I’ve checked, both old and new systems go through same code, though they go via UIKeyCommand which might introduce some quirks. I’ve tried it via pairing Apple bluetooth keyboard to iPad.

The only downside right now is that we’re not layout independent there, e.g. if you physically change your keyboard input language to something like AZERTY, input system package will fail to correctly recognize Q/A locations, though this setting is hidden very deep in iOS settings (this is different one to your onscreen keyboard language), same story on Android.

Mouse on Android works also.
Mouse on iOS might work, I haven’t tried, but it’s likely to be the same way as mouse would work with any iOS application then.

GCKeyboard and GCMouse are not supported as of right now. Would you folks mind reporting a bug via Help->Report a Bug so we can keep track of it? Thanks!

1 Like

First, thanks for your answer.

I will do a bug report (containing a link to this conversation) about this.

About the keyboard:

  • The fact that it’s not layout independent is a problem, but if it’s the only issue here, it’s acceptable. We can do a rebind menu.
  • It’s not the only issue with the keyboard though. I noticed that if I press a key (in this example, ’ = ’ key), the action is sent only if I wait like 0.5s between each physical key press. I’ve made a record with the Input debugger connected to the iPad (that is an AWESOME tool by the way, good job here). I press and release the ’ = ’ key. Sometimes I wait AFTER releasing the key, sometimes I spam the key. Notice how the only difference is the “Format=KEYS”. If this is present, the action works as expected.
  • Please note that if we’re using the keyboard in an input field it works fine. What I said is only valid for “gameplay” inputs (like WASD movement for instance)
  • I tested with the magic keyboard and with a bluetooth keyboard.

https://www.youtube.com/watch?v=EksMYIm9goA

About the mouse:

  • It’s recognized as a touch. I checked all the InputDevice and there’s no mouse. I checked with a mouse connected in bluetooth and with the magic keyboard (trackpad). I can’t get the cursor position unless there’s a touch (= click).
  • I would love for the mouse to be recognized as a “Mouse” device.

Have a nice day.

1 Like

Ok I see, likely UIKeyCommand goes through Cocoa shortcut/combo recognizers or something first and that delays the input. Definitely GCKeyboard should be better here. Thanks for the bug, we will have a look.

1 Like

I think this issue is also causing issues in the ‘iOS apps on M1 Mac’ scenario, the keyboard inputs aren’t recognized properly, although I haven’t delved too deep into the cause of this.

@anatolyV is it the same behavior on iOS apps on Mac? aka input of some keys is delayed?

BTW I reported the bug. Case 1369022.

1 Like

No, sorry. Keyboard inputs are completely ignored under macOS.

1 Like

@anatolyV would you mind filing a separate bug report for keyboard support for iOS apps running under macOS on M1? Both old and new input systems are driven by same cocoa touch code here, so if one doesn't work for you it's likely another also doesn't work. I've asked around and there is at least one report that it worked a while ago, but we need to recheck then.

Alright, and just as another bit of info, input fields do work as expected. If I file a bug report on this particular, should I submit a repro project as well? Wouldn’t be too hard to create one considering what the issue is but I would still need to carve out a bit of time for that.

@anatolyV Yes bug reports do need a repro case so our QAs can test them, I guess something like this will do:

using System;
using UnityEngine;
using UnityEngine.InputSystem;

public class TestScript : MonoBehaviour
{
    void Update()
    {
        foreach (var keyCode in (KeyCode[]) Enum.GetValues(typeof(KeyCode)))
        {
            if (Input.GetKeyDown(keyCode))
                Debug.Log($"old input, {keyCode} pressed");

            if (Input.GetKeyUp(keyCode))
                Debug.Log($"old input, {keyCode} released");
        }

        if (Keyboard.current == null)
            return;
       
        foreach (var keyCode in (Key[]) Enum.GetValues(typeof(Key)))
        {
            if (keyCode == Key.None || keyCode == Key.IMESelected)
                continue;
       
            if (Keyboard.current[keyCode].wasPressedThisFrame)
                Debug.Log($"new input, {keyCode} pressed");
       
            if (Keyboard.current[keyCode].wasReleasedThisFrame)
                Debug.Log($"new input, {keyCode} released");
        }
    }
}

// and in separate file
using UnityEngine;
public class LogPrinter : MonoBehaviour
{
    private string log;
    void OnEnable () {
        Application.logMessageReceived += HandleLog;
    }
    
    void OnDisable () {
        Application.logMessageReceived -= HandleLog;
    }
    void HandleLog(string logString, string stackTrace, LogType type){
        log = $"\n{Time.timeAsDouble:F2} {logString}{log}";
        if (log.Length > 1000)
            log = log.Substring(0, 1000);
    }
    void OnGUI () {
        GUILayout.Label(log);
    }
}

I don’t immediately have direct access to M1 macbook so unfortunately can’t test it right now

1 Like

After installing iOS 15 on my iPad and iPhone, all external input from a Bluetooth keyboard is ignored unless you are in an active typing field. Tried the legacy input system, the new input system, as well as rewired plugin. They all work in iOS 14.x but once I updated to iOS 15, all keyboard input except for input fields do not register. (as in key being pressed to do something in code vs. typing in a text field) Tried 2019.4.32f1 & 2020.3.21f1.

Old Legacy Input System

void Update()
{
     if (Input.GetKeyDown(KeyCode.A))
     {
          //Do Something
     }
}

New Input System

void Update()
{
     var keyboard = Keyboard.current;
     if (keyboard == null)
          return;

     if (keyboard.aKey.wasPressedThisFrame)
     {
          //Do Something
     }
}

I can’t get either of these to work in iOS 15 on a Bluetooth keyboard, but they work on macOS, Windows, & Android. and iOS 14.x and earlier.

Is there something I’m missing?

@Vincent-Parker-WB Hi, would you mind to create a bug report for iOS 15 problem specifically so I can forward it to mobile team? Thanks!

I have the same issue. Our music app uses bluetooth pedal to turn pages.
And after updating to iOS 15 the “Up Arrow” and “Down Arrow” commands that come from pedal are ignored and the users are complaining that they can use pedal in other apps, but not in ours.
We’re using Unity 2020.3.7f1 and
if (Input.GetKeyUp(KeyCode.UpArrow))

Hello! I’ve made a native iOS plugin to make iPad keyboards working in my project (Pixel Studio).
Now it’s available on the Asset Store.

7726062--970038--CardImage.png

Hi folks, I found where the issue is, because we currently using UIKeyCommand for keyboard input (I know I know, we plan to use GCKeyboard going forward, but it’s still some time into the future), iOS 15 has a change in behavior where system handlers take precedence over ours, so none of the input is reaching any of backends. The current fix is to set “wantsPriorityOverSystemBehavior” to YES for all commands. If you’re blocked by this you can do it manually in UnityView+Keyboard.mm that is part of iOS player.

In meanwhile I’m fixing it as part of Unity Issue Tracker - Keyboard input is not working when using an external keyboard in iOS 15 and will backport to all supported versions.

Good news! I’ll wait for resolution, thanks!