> For the complete documentation index, see [llms.txt](https://university-of-games.gitbook.io/welcome/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://university-of-games.gitbook.io/welcome/products/utilities/virtual-keyboard.md).

# Virtual Keyboard

Virtual Keyboard for Unity — on-screen uGUI keyboard for 2D, 3D and VR. Docs by University of Games.

**Virtual Keyboard for 2D/3D and VR experiences** is an on-screen ASCII keyboard from University of Games. Drop a Canvas-based keyboard into your UI so players can type without a physical keyboard — kiosks, consoles, mobile overlays, and world-space canvases in VR/AR.

{% hint style="success" %}
**Get it on the Unity Asset Store:** [Virtual Keyboard for 2D/3D and VR experiences](https://assetstore.unity.com/packages/tools/input-management/virtual-keyboard-for-2d-3d-and-vr-experiences-86828)
{% endhint %}

{% hint style="info" %}
**Who is this for?** Indie developers building text entry where the system keyboard is unavailable, unwanted, or insufficient — including VR/AR apps with world-space UI.
{% endhint %}

{% hint style="success" %}
**Requirements:** Unity **2021.2+** (verified on **Unity 6 / 6000.0+**) · **Unity UI (uGUI)** · **EventSystem** in the scene · Prefab under a `Resources` folder
{% endhint %}

***

## In plain language — what do you get?

Four runtime scripts plus a ready keyboard prefab:

1. **ASCII keyboard prefab** — letters, Shift, Alt (numbers/symbols), Space, Backspace and Done.
2. **Simple Open / Close API** — `VirtualKeyboard.Open`, `Close`, `IsOpen`.
3. **Caret-aware typing** — insert and delete at the cursor via `InputFieldCaretPosition`.
4. **Reflection-based text binding** — writes any public `text` property on the bound input object.
5. **Easy restyle** — uGUI Buttons + sprites; rename keys for other glyphs or languages.

***

## Quick start

{% stepper %}
{% step %}

### Install

Install from the [Unity Asset Store](https://assetstore.unity.com/packages/tools/input-management/virtual-keyboard-for-2d-3d-and-vr-experiences-86828), or copy `Assets/Virtual Keyboard/` into your Unity project.
{% endstep %}

{% step %}

### Open the demo

Open `Assets/Virtual Keyboard/Demo/Demo.unity` and press Play. Click **Show Keyboard**, type with the virtual keys, then **Hide Keyboard** or press **DONE**.
{% endstep %}

{% step %}

### Wire your own field

Add an **EventSystem** and a **Canvas**. Put **`InputFieldCaretPosition`** on your input GameObject, add **`OpenVirtualKeyboard`**, assign the Canvas, and call `OpenKeyboard()` from a Button (or `VirtualKeyboard.Open` from code).
{% endstep %}

{% step %}

### Customize

Edit `Resources/VirtualKeyboard.prefab` and sprites under `Textures/`. Full recipes live under Getting Started; restyling under Customization & Extending.
{% endstep %}
{% endstepper %}

***

## Features

<table data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><h3>⌨️</h3></td><td><strong>ASCII keyboard prefab</strong></td><td>Letters, Shift, Alt (numbers/symbols), Space, Backspace and Done — ready to instantiate.</td></tr><tr><td><h3>🎯</h3></td><td><strong>Caret-aware typing</strong></td><td>Insert and delete at the local caret position, similar to a native mobile keyboard.</td></tr><tr><td><h3>🔌</h3></td><td><strong>Simple static API</strong></td><td><code>VirtualKeyboard.Open</code>, <code>Close</code>, and <code>IsOpen</code> — no complex setup required.</td></tr><tr><td><h3>🧩</h3></td><td><strong>Reflection text binding</strong></td><td>Reads/writes any public <code>text</code> property on the bound input object.</td></tr><tr><td><h3>🎨</h3></td><td><strong>Easy to restyle</strong></td><td>uGUI Buttons + sprites; rename keys to target other languages or symbols.</td></tr><tr><td><h3>🥽</h3></td><td><strong>2D / 3D / VR ready</strong></td><td>Works on Screen Space or World Space canvases — place the Canvas in VR and point at keys.</td></tr></tbody></table>

***

## Documentation map

| Page                      | Contents                                                                                    |
| ------------------------- | ------------------------------------------------------------------------------------------- |
| Getting Started & Recipes | Install, demo, wire an input field, open/close recipes                                      |
| API Reference             | `VirtualKeyboard`, `OpenVirtualKeyboard`, `InputFieldCaretPosition`, `VirtualKeyboardASCII` |
| Customization & Extending | Sprites, key names, languages, World Space / VR, limits, troubleshooting                    |

***

## Architecture

```mermaid
flowchart TD
    UI["Button / OpenVirtualKeyboard"] --> Open["VirtualKeyboard.Open(canvas, inputObject)"]
    Open --> Load["Resources.Load VirtualKeyboard prefab"]
    Load --> Parent["Parent under Canvas"]
    Parent --> Bind["Bind inputObject"]

    Key["Key Button OnClick"] --> OKD["VirtualKeyboardASCII.OnKeyDown"]
    OKD -->|DONE| Close["CloseKeyboard"]
    OKD -->|SHIFT / ALT| Layout["Refresh active board"]
    OKD -->|char / SPACE / BACKSPACE| Send["VirtualKeyboard.SendKeyString"]

    Send --> Caret["InputFieldCaretPosition caret index"]
    Send --> Text["text get/set via reflection"]
    Send --> Focus["Reactivate InputField next frame"]
```

### Design notes

1. **Resources prefab** — `Open` instantiates `Resources/VirtualKeyboard`; keep that path.
2. **Caret subclass** — typing needs `InputFieldCaretPosition`, not a plain `InputField`.
3. **Key = GameObject name** — `OnKeyDown` inserts `key.name` (special names: `DONE`, `SHIFT`, `ALT`, `BACKSPACE`, `SPACE`).
4. **One active keyboard** — opening for a different `inputObject` closes the previous instance.

***

## Package layout

```
Assets/Virtual Keyboard/
├── Demo/
│   └── Demo.unity                 # Sample Show / Hide + input field
├── Resources/
│   └── VirtualKeyboard.prefab     # Runtime keyboard (Resources.Load)
├── Scripts/
│   ├── VirtualKeyboard.cs              # Open / Close / text / SendKeyString
│   ├── VirtualKeyboardASCII.cs         # Layouts + OnKeyDown
│   ├── OpenVirtualKeyboard.cs          # UI helper
│   └── InputFieldCaretPosition.cs      # Caret-aware InputField
├── Textures/                      # Button and icon sprites
└── README.md
```

***

## Version history

{% updates format="short" %}
{% update date="2024-12-30" tags="compat" %}

## Asset Store update

Package maintained for current Unity releases; demo scene verified on Unity 6 (`6000.0.x`). Original store baseline listed as Unity 2021.2.9.
{% endupdate %}

{% update date="2017-01-01" tags="major" %}

## Initial release

Canvas ASCII keyboard prefab, `VirtualKeyboard` static API, Shift/Alt layouts, caret-aware `InputFieldCaretPosition`, and demo scene for 2D/3D/VR-style UI entry.
{% endupdate %}
{% endupdates %}

***

## Support

Questions about the package? Reach us via the [Unity Asset Store publisher page](https://assetstore.unity.com/publishers/25633) or the channels listed under [Community](/welcome/community.md).
