The built-in UnityEngine.Input system doesn't recognize external keyboards for iPad & iPhone. This asset allows you to get key input from Magic & Smart Keyboard, as well as from other external bluetooth keyboards.
DISCLAIMER:
Unity somehow supports external keyboards for old iOS versions. For example, UnityEngine.Input works on my iPhone 5 running on iOS 12, but doesn't work on iPad running on iOS 15. Maybe it's a bug and it will be resolved soon. I hope.
System requirements:
● Any version of Unity.
● iOS/iPadOS 13.4+ (plugin code will ignored on old devices).
Usage:
● Check Demo.scene and Demo.cs script first.
● Add ExternalInput script to your scene (it should be active).
● Use UniversalInput instead of UnityEngine.Input (or use ExternalInput in addition to UnityEngine.Input).
● Both UniversalInput and ExternalInput have the same syntax as UnityEngine.Input (GeyKeyDown, GetKey, GetKeyUp, anyKey)
● Alternatively you can subscribe to ExternalInput.OnKeyDown and ExternalInput.OnKeyUp events to get UIKey objects representation from iOS.
● For any class description please refer to XML-comments in code.
Additional setup in Xcode:
● After building your Xcode project, find ExternalInput.xib, navigate to [Target Membership] section and check [Unity-iPhone].
Notes:
● Modifier keys (like Shift, Control, Alt and other) may be received both from UIKey.keyCode (UIKeyboardHIDUsage) and UIKey.modifierFlags (UIKeyModifierFlags).
● Secondary keys (like !, @, #, $, %, ^, &, * and other) may be received from UIKey.characters (string). At the same time, UIKey.keyCode will be a primary key with a modifier in UIKey.modifierFlags.
● If you need to change key mapping, please edit KeyCodeMapping.KeyCodeDictionary.
References:
● KeyCode
● UIKey
● UIKeyboardHIDUsage
● UIKeyModifierFlags
Support:
● Discord - questions, live chat with developers
The asset icon was made by FR_Media.
It would be super awesome if you rate ★★★★★ my asset and leave your feedback! Your reviews inspire me for creating and improving my assets, thanks!