Skip to content

UI Keyboard

Updated

An on-screen letter keyboard.

Type
ent-ui-keyboard
Script class
UIKeyboardEntity
Family
UI

A UI Keyboard is a keyboard drawn inside the scene, pressed with a mouse, a finger or an XR controller ray. Its keys type into whichever UI Input has focus, so one keyboard serves every field in the scene.

You often do not need to place one: when a field gains focus in a headset without a system keyboard, or on any device when the field has virtualKeyboard: true, the runtime opens its own shared keyboard. Place a UI Keyboard yourself for a keyboard that stays in a fixed place, such as on a kiosk or under a sign-in panel. It can be a root in world space at its transform, or nested in a panel.

The keyboard carries one of two layouts:

  • UI Keyboard QWERTY (comp-ui-keyboard-qwerty, what a new keyboard starts with): letters, digits, backspace, space and enter. Shift capitalizes the next letter, ?123 opens a page of symbols and ABC returns to letters.
  • UI Keyboard Numeric (comp-ui-keyboard-numeric): 0 to 9, ., -, backspace and enter.

To switch layouts, add the other layout component; it replaces the current one. Scripts reach either layout as UIKeyboardComponent.

A new keyboard already has a Signal Emitter on the signal ui:keyboard, and so does the one the runtime opens. It reports UIKeyboard::press with { key } for every key that types (the character, or backspace, space or enter; Shift and page switches send nothing), and UIKeyboard::show and UIKeyboard::hide.

The props that matter most:

  • color: the key hover colour.
  • opacity: the alpha of the keyboard’s fill.
  • padding and margin: the space inside and around the keyboard, in layout pixels (px).

From a script, show(), hide() and isShown() on the layout component show, hide and query the keyboard.

  1. Add a UI Keyboard where it should stay: at the scene root or under a 3D object for a free-standing keyboard, or under a UI Panel. See Scenes and hierarchy.
  2. Keep the QWERTY layout, or add UI Keyboard Numeric for a keypad.
  3. Place a UI Input nearby; pressing it gives it focus, and the keyboard types into it.
  4. Listen on ui:keyboard if a script should react to keys.

Goal: play a short click for every key pressed on any in-scene keyboard.

KeyClick.jx
#pragma lifecycle(startup)
// Scene: an Audio entity named 'Key Click' that plays a short click (repeat: 'once').
function startup() {
const click = findEntity('Key Click').getComponent(AudioComponent);
on('ui:keyboard', (event) => {
if (event.eventType === EventType.UIKeyboard.Press) click.play();
});
}

How it works:

  • Every keyboard entity reports on ui:keyboard without any setup, including the one the runtime opens by itself.
  • UIKeyboard::press arrives for each key that types, so Shift and page switches stay silent.

Goal: a fixed numeric keypad on a kiosk appears when a button is pressed and hides once enter is pressed.

Keypad.jx
#pragma lifecycle(startup)
// Scene: a UI Keyboard named 'Keypad' with the UI Keyboard Numeric layout,
// a UI Input named 'Amount', and a UI Button named 'Enter Amount' (Signal Emitter: 'kiosk:amount').
function startup() {
const keypad = findEntity('Keypad').getComponent(UIKeyboardComponent);
findEntity('Amount').getComponent(UIInputComponent).setProps({ text: 'Amount', type: 'number' });
keypad.hide();
on('kiosk:amount', (event) => {
if (event.eventType === EventType.UIButton.Press && !keypad.isShown()) keypad.show();
});
on('ui:keyboard', (event) => {
if (event.eventType === EventType.UIKeyboard.Press && event.data.key === 'enter') keypad.hide();
});
}

How it works:

  • getComponent(UIKeyboardComponent) returns the keyboard’s layout, whichever one it carries.
  • hide() at start keeps the keypad out of the way; the button calls show() when it is needed.
  • The enter key arrives as { key: 'enter' }, and the script hides the keypad.

Goal: echo each key in a label, for a typing tutorial.

KeyEcho.jx
#pragma lifecycle(startup)
// Scene: a UI Keyboard, a UI Input, and a UI Label named 'Last Key'.
const NAMES = { backspace: '⌫ Backspace', space: '␣ Space', enter: '⏎ Enter' };
function startup() {
const label = findEntity('Last Key').getComponent(UILabelComponent);
on('ui:keyboard', (event) => {
if (event.eventType === EventType.UIKeyboard.Show) label.setProps({ text: 'Start typing' });
if (event.eventType === EventType.UIKeyboard.Press) {
const key = event.data.key;
label.setProps({ text: `You pressed: ${NAMES[key] ?? key}` });
}
});
}

How it works:

  • Character keys arrive as the character itself; the three special keys arrive by name and are turned into readable text.
  • UIKeyboard::show resets the label each time the keyboard appears.

What a new UI Keyboard is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.

Component Type Role Per entity What it does
Layer comp-layer Required One Puts the entity on a render/raycast layer so cameras and rays can include or skip it.
Lock comp-lock Required One Editor-only flag that stops the entity from being selected or moved.
Enable comp-enable Required One Turns the entity and its children on or off: hides them and stops their behavior.
Transform comp-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
UI Keyboard Qwerty comp-ui-keyboard-qwerty Starts with One An on-screen letter keyboard.
Signal Emitter comp-signal-emitter Starts with Several Collects events from sibling components and sends them on as signals.

You can also add 1 optional components, such as UI Keyboard Numeric.

The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).

Prop Default Range
signal "ui:keyboard"

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

  • UIKeyboard::press
  • UIKeyboard::show
  • UIKeyboard::hide

Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.

Run it in the browser, read its scripts, and download it as an XR Creator project.

Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My UI Keyboard.

UIKeyboardEntity.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My UI Keyboard');
if (!(entity instanceof UIKeyboardEntity)) return;
// Its UI Keyboard Qwerty component holds the settings listed under Props.
const component = entity.getComponent(UIKeyboardQWERTYComponent);
log(component.props);
}