Keyboard

class : MonoBehaviour

A 3D, on-screen keyboard that you can programmatically place in your scene.

The keyboard is a web UI that runs inside a WebViewPrefab instance and emits messages to the C# to indicate when characters have been pressed. The keyboard UI is open source and available on GitHub.

Example:

// First, create a WebViewPrefab for our main web content.
var mainWebContent = WebViewPrefab.Instantiate(0.6f, 0.3f);
mainWebContent.transform.parent = transform;
mainWebContent.transform.localPosition = new Vector3(0, 0f, 0.4f);
mainWebContent.transform.LookAt(transform);
mainWebContent.Initialized += (sender, e) => mainWebContent.WebView.LoadUrl("https://www.google.com");

// Add the keyboard under the main webview.
var keyboard = Keyboard.Instantiate();
keyboard.transform.parent = mainWebContent.transform;
keyboard.transform.localPosition = new Vector3(0, -0.31f, 0);
keyboard.transform.localEulerAngles = new Vector3(0, 0, 0);
// Hook up the keyboard so that characters are routed to the main webview.
keyboard.InputReceived += (sender, e) => mainWebContent.WebView.HandleKeyboardInput(e.Value);

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
  • Russian
  • Danish
  • Norwegian
  • Swedish

Summary

Public properties

WebViewPrefab

WebViewPrefab WebViewPrefab

The WebViewPrefab instance used for the keyboard UI.

Public methods

Init

void Init(float width, float height)

Initializes the keyboard with the specified width and height. Instantiate() calls this method for you, so you only need to call this method directly if you place the Keyboard.cs script on your own custom object.

Instantiate

static Keyboard Instantiate()

Creates and initializes a Keyboard instance using the default width and height.

Instantiate

static Keyboard Instantiate(float width, float height)

Creates and initializes a Keyboard instance using the specified width and height.

Public events

Initialized

EventHandler Initialized

Indicates that the keyboard finished initializing.

InputReceived

EventHandler<EventArgs<string>> InputReceived

Indicates that the user clicked a key on the keyboard.