UI Toolbox logoUI Toolbox

KeyBindingField

KeyBindingField in UIToolbox is a field for a key or button binding in a settings screen. Its value is an Input System control path such as <Keyboard>/space or <Gamepad>/buttonSouth. A click, Enter or the gamepad submit button starts the capture. The next key or button becomes the value. The capture is the Input System interactive rebind on a temporary action, so the paths are generic: a press on any gamepad gives <Gamepad>/.... The field needs the Input System package and an active input handler that includes it.

<tb:KeyBindingField name="jump" label="Jump" value="&lt;Keyboard&gt;/space" />
<tb:KeyBindingField name="jumpPad" label="Jump (pad)" devices="Gamepad" />
// Apply the value to an action. An empty value turns the binding off.
jumpField.RegisterValueChangedCallback(evt => jumpAction.ApplyBindingOverride(0, evt.newValue));
Member Description
value The control path, or an empty string for no binding.
Devices KeyBindingDevices flags: Keyboard, Mouse, Gamepad, All. Default keyboard and gamepad.
EmptyText, PromptText The text for an empty value ("None") and during the capture ("Press a key").
StartListening(), CancelListening(), IsListening The capture. A cancel keeps the value.
DisplayText The text that the field shows, for example "Space", "A" or "LMB".
ConflictGroup (conflict-group) A group name. The fields of the group must have different values. Empty (default) makes no check.
HasConflict True while a different field of the group has the value of this field.

Conflicts

Some games let two actions have the same key, so the check is optional. Give the fields that must be different the same conflict-group:

<tb:KeyBindingField label="Jump" value="&lt;Keyboard&gt;/space" conflict-group="keys" />
<tb:KeyBindingField label="Crouch" value="&lt;Keyboard&gt;/c" conflict-group="keys" />

Styling

Class Element
tb-key-binding-field The field. It is a BaseField, so the native label and input classes apply too.
unity-base-field__input The key cap: --tb-color-surface-alt with a --tb-color-border border, 2 px at the bottom. --tb-color-surface-hover on hover, and an --tb-color-accent border with the focus.
tb-key-binding-field__key The text of the binding, bold --tb-color-text.
tb-key-binding-field--empty No binding: normal --tb-color-text-muted text.
tb-key-binding-field--listening During the capture: the cap is --tb-color-accent with italic --tb-color-accent-text text.