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.
How to Use¶
In order to use the VRKeyboard you must follow the steps below:
Drag and Drop the VRKeyboardFull prefab in your scene from the Packages → com.oramavr.mages → Runtime → MAGES → SDKAddons → VRKeyboard → VRKeyboard → Prefabs folder.
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
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.
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.
If you need to attach extra KeyLayouts in the VRKeyboard do it before calling the
void Initialize() function.
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.
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)
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.
If not already done through the editor, you can attach here the UnityAction Events to be called in
Finally, you can use the
void GetInputBuffer()function to retrieve the new/edited string.
In order to improve CPU performance this can be called when the
UnityAction OnAnyTextKey() is invoked, instead of every frame.
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
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:
Go to the ToolBar and click on Assets → Create → VRKeyboard → KeyLayout. This will create a new empty KeyLayout.
Go to the Inspector and edit the KeyLayout.
string layoutNameis for the name you want to be displayed in the spacebar. Usually used for language name (e.g. “English”, “Greek”)
List<string> mainKeysis the list holding all the letter bindings of the main keys.
List<string> shiftMainKeysis the list holding all the letter bindings of the main keys when shift button is enabled.
List<string> alternativeKeysis the list holding all the letter bindings of the alternative keys accessed by pressing the “#!1” Button and in page 1.
List<string> alternativeKeysis 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.
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.
Attach the new
KeyLayoutcreated to the
VRKeyboardControllerscript 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.
By default the VRKeyboard has two KeyLayouts with English and Greek letters.