VR Keyboard

The MAGES SDK has a versatile, customizable and easy to use VRKeyboard that fits every need. It supports custom languages as well as layouts and can be attached in any GameObject. Below there is a How To Use and a Customization section.

../../../_images/VRKeyboardPreview.png

How to Use

In order to use the VRKeyboard you must follow the steps below:

  1. Drag and Drop the VRKeyboardFull prefab in your scene from the Packages → com.oramavr.mages → Runtime → MAGES → SDKAddons → VRKeyboard → VRKeyboard → Prefabs folder.

Note

You can either place the keyboard at a desired static position or as a child of a GameObject.

This Prefab has the VRKeyboardController script attached, which is responsible for the Keyboard Interaction and Settings

  1. Call the bool Initialize() on the Start Function of your custom script. This will set the Keyboard’s Layout to the first KeyLayout in the list KeyLayouts shown in inspector.

Warning

If the Intialize() function returns false, it means that there is a problem with the attached Key Layouts, check them in the inspector and fix it to continue.

Note

If you need to attach extra KeyLayouts in the VRKeyboard do it before calling the void Initialize() function.

  1. Give the string you want to edit to the keyboard using the void InitializeInputBuffer(string inputBuffer) function. This will pass the string to the keyboard, and it will set the caret position at the end of it.

Note

Alternatively, you can set the input buffer using the void SetInputBuffer(string inputBuffer) which will only set the string you want to be edited by the keyboard. Then you can use the void SetCaretPosition(int position) to set a custom caret position in the string. (The position is clamped from 0 to the length of the string in the input buffer)

  1. Use the void SetSubmitText(string text) to modify the enter button’s text according to the application’s needs. This step is optional and if not done the default text “OK” will appear.

  2. If not already done through the editor, you can attach here the UnityAction Events to be called in UnityAction OnSubmit(), UnityAction OnTab(), UnityAction OnAnyTextKey() and UnityAction OnAnyKey() actions.

  3. Finally, you can use the void GetInputBuffer() function to retrieve the new/edited string.

Note

In order to improve CPU performance this can be called when the UnityAction OnAnyTextKey() is invoked, instead of every frame.

Keyboard Customization

Customizing the Look and Feel

The keyboard can be customized for button looks as well as sound and haptic feedback. On the text field of every key on the keyboard there is the VRKeyHighlightAndHaptic script. This is responsible for the sounds, haptics and transitions.

Adding Custom Layouts/Languages

Through our KeyLayout Scriptable object the MAGES SDK has you can easily create new Layouts for the VRKeyboard. In order to create a new Layout follow the steps below:

  1. Go to the ToolBar and click on Assets → Create → VRKeyboard → KeyLayout. This will create a new empty KeyLayout.

../../../_images/KeyLayoutCreation.png
  1. Go to the Inspector and edit the KeyLayout.

    Note

    • The field string layoutName is for the name you want to be displayed in the spacebar. Usually used for language name (e.g. “English”, “Greek”)

    • The field List<string> mainKeys is the list holding all the letter bindings of the main keys.

    • The field List<string> shiftMainKeys is the list holding all the letter bindings of the main keys when shift button is enabled.

    • The field List<string> alternativeKeys is the list holding all the letter bindings of the alternative keys accessed by pressing the “#!1” Button and in page 1.

    • The field List<string> alternativeKeys is the list holding all the letter bindings of the alternative keys accessed by pressing the “#!1” Button and in page 2.

    • You can also import the key bindings from a txt file. Switch to the Import Utilities Tab and add the file path as well as the separator in the fields. Then Click Import From File.

    Warning

    The keys must be assigned in the order you want them to be displayed. The script assigns them line-by-line from left to right in the blank spots of the VRKeyboard prefab.

  2. Attach the new KeyLayout created to the VRKeyboardController script found in the VRKeyboardFull prefab instance you have on the scene. This will enable the new prefab, and it will be cycled through using the language change button of the VRKeyboard.

Note

By default the VRKeyboard has two KeyLayouts with English and Greek letters.