Class Kbd
A keyboard shortcut hint, rendered as one or more key caps.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class Kbd : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
Kbd renders a shortcut the way a keyboard does: each token sits in its own cap, a raised surface with a strong border and a thicker bottom edge that gives it the depth of a physical key.
There are two forms, mirroring the web implementation. Set keys for a combo and every token gets its own cap. Set text for a single token and you get one cap. keys wins when both are set; clearing it falls back to text.
Kbd is a hint, not a control. It ignores pointer events and is not focusable.
Examples
A single key.
var kbd = new Kbd { text = "Esc" };
parentElement.Add(kbd);
A combo, one cap per token.
var shortcut = new Kbd { keys = new List<string> { "Ctrl", "Shift", "K" } };
parentElement.Add(shortcut);
Both forms in UXML. The keys attribute takes a comma separated list.
<appui:Kbd text="Esc" />
<appui:Kbd keys="Ctrl,K" />
Constructors
Kbd()
Default constructor.
Declaration
public Kbd()
Fields
capUssClassName
The styling class of a single key cap.
Declaration
public const string capUssClassName = "appui-kbd__cap"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The Kbd main styling class.
Declaration
public const string ussClassName = "appui-kbd"
Field Value
| Type | Description |
|---|---|
| string |
Properties
keys
The tokens of a key combo, one cap each.
Declaration
[CreateProperty]
[UxmlAttribute]
public List<string> keys { get; set; }
Property Value
| Type | Description |
|---|---|
| List<string> |
Remarks
Takes precedence over text. Set it to null or an empty list to fall back to the single cap form.
text
The single key token to display.
Declaration
[CreateProperty]
[UxmlAttribute]
public string text { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Used only while keys is null or empty. Defaults to an empty string, which still renders one empty cap so the element always has the shape of a key.