# Keys and shortcuts

Use key events for commands and text events for text. An arrow key can move a selection; the characters a person types may come from an IME, an on-screen keyboard, or a layout that has little in common with the key's name.

The [keyboard pad](../focus/index.md) is a complete example: it handles Left, Right, and Escape in `OnKeyDown`, sets `Handled` only for those commands, and redraws when its state changes.

## Handle the smallest command

Override `OnKeyDown(ref KeyEventRef e)` on a focusable view. Compare `e.Key` with `VirtualKey` values. Leave unrelated keys alone and call the base implementation when you extend a control that already handles editing.

`IsRepeat` tells you that the key is being held. Repetition suits arrow-based adjustment, but a one-shot action should usually reject repeats. `Shift` is the available modifier flag; for selection, Shift commonly extends a range rather than replacing it.

`RootView` reserves Tab/Shift+Tab for focus traversal. Normal key events go to the focused view, not through the pointer tunnel/bubble route. A parent page does not automatically receive every child's unhandled key as a global shortcut.

## Know the current shortcut limit

`KeyEventRef` does not expose Control, Alt, or Command/Meta modifier-state properties. `VirtualKey.Control` is a key code, not a way to ask whether Control is held during another event. The shared abstraction also has no key-up callback suitable for reconstructing a portable modifier state machine.

The browser bridge currently skips Ctrl/Meta/Alt-modified key events. Do not implement or advertise a cross-platform Ctrl+S or Command+S by inventing fields such as `e.Control`. Use an explicit action control or an unmodified key within a focused tool, and isolate any native shortcut integration at the platform edge.

## Do not synthesize text from key codes

`OnChar` carries committed character input through `KeyEventRef.Character`. `TextBox` and ToolKit `TextInput` already connect that input to their editing state. A letter key code is not the final character after layout, composition, or dead-key processing.

For application-specific commit behavior, see [Custom text editors](../custom-editors/index.md). For composed text and the limitations of individual runtime bridges, read [IME and soft keyboards](../ime/index.md) before treating a key press as a completed text edit.
