CanvasKeyboard

class : MonoBehaviour

Namespace: Vuplex.WebView

Like the Keyboard prefab, except optimized for use in a Canvas. You can add a CanvasKeyboard to your scene either by dragging the CanvasKeyboard.prefab file into a Canvas via the editor or by programmatically calling CanvasKeyboard.Instantiate(). For an example, please see 3D WebView's CanvasWorldSpaceDemo scene.

Important note

2D WebView for WebGL doesn't support CanvasKeyboard due to a browser limitation where clicking on the keyboard causes it to steal focus from webviews.

Summary

Public properties

CustomKeyboardUrl

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".

Resolution

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

CanvasWebViewPrefab? WebViewPrefab { get; }

Gets the CanvasWebViewPrefab 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.

Example

await keyboard.WaitUntilInitialized();
keyboard.WebViewPrefab.Clicked += (sender, eventArgs) => {
    Debug.Log("Keyboard was clicked");
};

Public methods

Instantiate

static Keyboard Instantiate()

Creates a new instance

Example

// Create a CanvasKeyboard.
var keyboard = CanvasKeyboard.Instantiate();
keyboard.transform.SetParent(canvas.transform, false);
var rectTransform = keyboard.transform as RectTransform;
rectTransform.anchoredPosition3D = Vector3.zero;
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
rectTransform.sizeDelta = new Vector2(650, 162);

WaitUntilInitialized

Task WaitUntilInitialized()

Returns a task that completes when the keyboard is initialized, which means that its WebViewPrefab property is ready for use.

Example

await keyboard.WaitUntilInitialized();
keyboard.WebViewPrefab.Clicked += (sender, eventArgs) => {
    Debug.Log("Keyboard was clicked");
};

Public events

Initialized

EventHandler Initialized

Indicates that the keyboard finished initializing.

KeyPressed

EventHandler<EventArgs<string>> KeyPressed

Indicates that the user pressed a key on the keyboard.