Skip to content

Keyboard

Benedikt Hensen edited this page Oct 30, 2018 · 4 revisions

Keyboard

There are two 3D keyboards provided with this framework: A full text keyboard and a numeric keyboard. They are both saved as prefabs in the resource folder so that they can be loaded via code. Both keyboard types consist of a Keyboard script and several Key scripts. Furthermore there is a BluetoothKeyboard script which handles user input on a bluetooth keyboard and applies this input the the 3D keyboard.

The Keyboard script automatically finds all key objects which are children. It also provides static Display(...) methods in order to quickly instantiate and initialize the keyboard from code. Define a callback-method and provide it to the display-method. The callback method should take one string as an argument. When the user inputs is finished, this string will contain the input result.

If the user cancels the input, the string argument will be set to null. This must be checked in the callback method.

The keyboard is defined as a Window and is thus considered by the WindowManager.

Keyboard

Keys

The keys can have several KeyTypes: LETTER, ENTER, BACKSPACE, ACCEPT, CANCEL which define their behavior when they are pressed.

Overview of the OnPressed behavior

  • KeyType.LETTER: adds the provided string for letter to the text of the keyboard.
  • KeyType.ENTER: adds a new line to the text of the keyboard
  • KeyType.BACKSPACE: removes the last char from the text of the keyboard.
  • KeyType.ACCEPT: calls Accept() on the Keyboard. This provides the user input to the defined callback-method.
  • KeyType.CANCEL: calls Cancel() on the Keyboard. This provides a null-string to the defined callback-method.

Note that if if the key type is set to Letter, the key gameobject is automatically renamed to "Key < letter >" and the assigned text- mesh caption is also set to the provided letter. This action is performed in the editor and at runtime.

Keys and Buttons

The keys are standard buttons which are augmented by a key component. This component communicates with the keyboard and maps the key's functionality to the behavior of the button.


Bluetooth Support

For bluetooth support, the BluetoothKeyboard is attached to the keyboard 3D object. At runtime, it creates a pseudo key of key type letter. If the user presses a button on the physical keyboard, this is registered by this script and the input is applied to the pseudo key as a letter. After that, the OnPressed method of the pseudo key is invoked in order to apply the input to the 3D keyboard.

See also

  • Button Template: Description of the button template which is the basis for the implemented keys
  • Buttons: Description of the different implemented buttons which are adapted to keys
  • Localization Manager: Sets the keyboard's language
Clone this wiki locally