A 3D, on-screen keyboard prefab that you can hook up to a webview for typing. You can add a Keyboard to your scene either by dragging the Keyboard.prefab file into it via the editor or by programmatically calling Keyboard.Instantiate(). For use in a Canvas, please see CanvasKeyboard instead.
The keyboard UI is a React.js app that runs inside a WebViewPrefab and emits messages to C# when keys are pressed. The keyboard UI is open source and available on GitHub.
The keyboard supports layouts for the following languages and automatically sets the layout based on the operating system's default language: English, Spanish, French, German, Italian, Russian, Danish, Norwegian, and Swedish.
Please note that 3D WebView's on-screen keyboard prefabs do not support Chinese, Japanese, or Korean. For those languages, please see this article about IME support and this section that describes how to enter characters for those languages programmatically.
string CustomKeyboardUrl
If you want to load a customized version of the Keyboard UI, you can do so by setting this field. For example, you could load a customized Keyboard UI from StreamingAssets by using a URL like "streaming-assets://keyboard/index.html".
float Resolution
Sets the keyboard's initial resolution in pixels per Unity unit.You can change the resolution to make the keyboard's content appear larger or smaller. For more information on scaling web content, see this support article.
WebViewPrefab? WebViewPrefab { get; }
Gets the WebViewPrefab used for the keyboard UI, or null
if the keyboard hasn't finished initializing yet. You can use WaitUntilInitialized() to detect when the WebViewPrefab property is ready to use.
await keyboard.WaitUntilInitialized();
keyboard.WebViewPrefab.Clicked += (sender, eventArgs) => {
Debug.Log("Keyboard was clicked");
};
static Keyboard Instantiate()
Creates an instance using the default width and height.
// Add a keyboard under a WebViewPrefab.
var keyboard = Keyboard.Instantiate();
keyboard.transform.SetParent(webViewPrefab.transform, false);
keyboard.transform.localPosition = new Vector3(0, -0.31f, 0);
keyboard.transform.localEulerAngles = Vector3.zero;
static Keyboard Instantiate(float width, float height)
Like Instantiate(), but creates an instance using the specified width and height.
Task WaitUntilInitialized()
Returns a task that completes when the keyboard is initialized, which means that its WebViewPrefab property is ready for use.
await keyboard.WaitUntilInitialized();
keyboard.WebViewPrefab.Clicked += (sender, eventArgs) => {
Debug.Log("Keyboard was clicked");
};
EventHandler<EventArgs<string>> KeyPressed
Indicates that the user pressed a key on the keyboard.