Overview
OnScreenKeyboard is an easy-to-use system to create and display on-screen keyboards (also known as virtual keyboards) within games. It supports custom keyboard layouts, custom look-and-feel, Text Mesh Pro integration, and more. The system is highly customizable, so you can tailor it to fit your needs.
Features
- Fully documented C# source code
- Supports custom keyboard layouts
- Supports transitions between layouts (such as lower/upper case, multiple languages, etc.)
- Custom look-and-feel
Purchase the OnScreenKeyboard from the Unity Asset Store here >>
Screenshots
Documentation
On Screen Keyboard is centered around the KeyboardManagerScript
mono behavior. At its core, this script creates the keyboard based on its assigned KeyboardLayout
. It uses an optional KeyboardButtonsDisplay
object to customize the look-and-feel of keys.
Options
Layout
The layout of the keyboard is controlled using a KeyboardLayout
object. The layout consists of a single text field which represents the actual keyboard layout – each line represents a row of keys. The line consists of a space-separated list of keys. Each key can be either a character, or a “placeholder” (such as “{shift}”). Optionally, a key can be followed by a column and the desired width of the key.
Let’s look at an example:
7 8 9
4 5 6
1 2 3
0:2 {reset}
The above will result in a keyboard with 4 rows of keys. The first 3 rows will each have 3 keys each. The bottom row has 2 keys, the first one twice as wide as the second one. The second key will have the value of “{reset}”.
KeyboardButtonsDisplay
A KeyboardButtonsDisplay object can be used to control the look-and-feel (aka display) of specific keys. It consists of a list of KeyDetails objects, which are used when creating the keyboard.
For each key being created, the manager searches for a relevant KeyDetails
object, and uses that to control the key creation.
Each KeyDetails
can control the following options:
Text
: This is used to change the text being displayed on the keyboard. For example, converting the value “{control}” from the layout with “Ctrl”Icon
: This allows displaying an icon on the key. This can be used to display an up-arrow for the “{shift}” button.- Colors: This allows overriding the default colors of the keyboard.
- Text Color
- Icon Color
- Background Color
KeyButtonScript
This script is used as the prefab script for a keyboard button. It supports controlling the text, icon and background image of the key.
Additional Scripts
In addition to the above scripts, On Screen Keyboards comes with two utility scripts
LayoutChanger
The LayoutChanger
script manages the transition between keyboard layouts in a centralized way. It can be used to transition between layouts based on a certain key being pressed (e.g., “{capslock}”) as well as transition back after a key press (e.g., “{shift}”). It can also be used to switch between languages.
TextboxLeyboardAdapterScript
The TextboxLeyboardAdapterScript
script makes it easy to bind a keyboard to a TextMeshPro InputField. It automatically listens to key presses on the keyboard and updates the input field as needed.