InputViewer
An InputViewer is a picture of a keyboard, a mouse or a gamepad that lights what is down. A key or a button lights at once and fades back after release, a stick shows its place with a short trail, and a trigger fills with its value. Use it in a tutorial video, a stream or for accessibility. It only shows the input; it never consumes or blocks it.


<!-- The keyboard or the gamepad that the player used last -->
<tb:InputViewer />
<tb:InputViewer device="Keyboard" layout="Compact" />
<tb:InputViewer device="Keyboard" layout="MouseOnly" />
<tb:InputViewer device="Gamepad" trail-length="24" />
<tb:InputViewer device="Both" show-mouse="false" />
var viewer = root.Q<InputViewer>();
viewer.Device = InputViewerDevice.Keyboard;
viewer.Layout = InputViewerLayout.Compact;
viewer.ShowMouse = false;
// Pause it while a menu is open
viewer.Paused = menu.IsOpen;
Members
| Member | Description |
|---|---|
Device (device) |
The picture, an InputViewerDevice: Auto (default) shows the keyboard or the gamepad by the device that the player used last, Keyboard, Gamepad, or Both side by side. |
Layout (layout) |
The keys of the keyboard, an InputViewerLayout: Full (default) has the function keys, the digits, the letters, the modifiers and the arrows; Compact has the WASD block, the arrows, the modifiers and the space bar; MouseOnly has no keys, only the mouse; Arrows, Wasd, LeftHand (Tab, Q W E R, A S D F, Shift, Ctrl, space), Numpad and FullWithNumpad show those keys only, so a tutorial step can show just the keys it needs. |
CustomLayout (custom-layout) |
The keys as text in the KeyboardLayout format with a KeyCode name for each key, for example Q W E R for an ability bar; a new line starts a row, {gap} leaves a space and {Space*4} sets a width. A lone digit is its Alpha key. Empty (default) uses Layout; text that does not parse or holds no key also uses Layout. |
PadParts (pad-parts) |
The parts of the gamepad that show, InputViewerPadParts flags: Sticks, Triggers, FaceButtons, Dpad, Shoulders, Menu. All (default) shows every part; the body always shows. |
FadeDuration (fade-duration) |
The time in milliseconds that a key or a button takes to fade back after release (default 300). |
TrailLength (trail-length) |
The number of last places of each stick that its trail shows (default 12). 0 shows no trail. |
ShowMouse (show-mouse) |
Shows the mouse next to the keyboard (default true). Its buttons light, and the wheel shows an arrow above or below the mouse that fades. |
ShowKeyboard (show-keyboard) |
Shows the keys of the keyboard (default true). Off hides them and leaves the mouse to ShowMouse. |
HideInTextFields (hide-in-text-fields) |
Lights no key typed into a focused password field (default true). Combos with Ctrl, Alt or Super still light. |
Paused (paused) |
Takes no new input (default false). The picture keeps what it shows, and the lights finish their fade. |
The gamepad:
- The face buttons show the glyphs of the gamepad in use, from
LastInputDevice.Family: A, B, X and Y on an Xbox gamepad, the shapes on a PlayStation gamepad, and the letters of a Switch gamepad. See GamepadGlyph. - A stick is a ring with a dot at its place and a trail whose last places fade. A click of the stick lights the ring.
- A trigger is a bar that fills with its value. The shoulders, the d-pad, the face buttons and Start and Select light like keys.
Notes:
- The viewer reads the input by itself while it is on a panel. With the Input System package it reads the keyboard, the mouse and the gamepads; with the Input Manager only the keyboard and the mouse.
- The key caps are a US keyboard, built once in the text format of
KeyboardLayout. The sticks, the triggers and the mouse are drawn withPainter2D, only while something moves or fades. The viewer makes no garbage while it runs. - The time of a fade is the real time, so the lights also fade while the game is paused.
- The viewer ignores the pointer, so it can lie over a game view.
Tips:
- For a stream, use the
Compactlayout in a corner of the game view, beside an InputEcho that names each input. MouseOnlysuits a game that the player plays with the mouse alone.- A longer
TrailLengthshows the path of a stick, such as a circle for a special move.
Styling
| Class or property | Element |
|---|---|
tb-input-viewer |
The viewer: a row with the keyboard, the mouse and the gamepad. |
tb-input-viewer__keyboard |
The keyboard. |
tb-input-viewer__row |
A row of keys. |
tb-input-viewer__key |
A key cap, a Label. |
tb-input-viewer__gap |
An empty space in a row of keys. |
tb-input-viewer__mouse |
The mouse. Its width and height are the size of the drawing. |
tb-input-viewer__gamepad |
The gamepad. Its width and height are the size of the drawing. |
tb-input-viewer__button |
A glyph of a face button on the gamepad. |
--tb-input-viewer-active |
A custom property on the viewer: the color of a light (--tb-color-accent). |
--tb-input-viewer-key |
A custom property on the viewer: the color of a key or a part (--tb-color-surface-alt). |
--tb-input-viewer-line |
A custom property on the viewer: the color of the outlines (--tb-color-border). |
--tb-input-viewer-key-size |
A custom property on the viewer: the largest width of one key in pixels (28). In a narrow parent the keys get smaller, so the widest row fits. A key too small for its name shows a short label, such as Ent, Bksp or NL. |
.stream .tb-input-viewer {
--tb-input-viewer-active: rgb(255, 200, 40);
--tb-input-viewer-key-size: 34;
}
.stream .tb-input-viewer__gamepad { width: 360px; height: 225px; }
The InputViewerDemo scene shows a keyboard with the mouse and a gamepad with its trails, every member in the Keyboard and Gamepad tabs, and a "Type here" field and a password field for the hide rule. The InputEchoDemo scene has a streamer layout with a compact viewer.