Overview
onKeyDown and onKeyUp attach global listeners on window, scoped to the component lifetime. Ideal for shortcuts that should be active while a view is mounted.
Handlers receive the native KeyboardEvent and may return a cleanup function. Listeners are removed automatically on unmount.
Keyboard hooks
|
API
|
Event
|
Notes
|
|---|---|---|
onKeyDown(fn)
| keydown | Most common for shortcuts (Escape, Cmd+K, etc.). |
onKeyUp(fn)
| keyup | Useful for modifier release (e.g. Shift for multi-select). |
onKeyDown — global key listener
onKeyDown listens for keydown events on the window. The listener is automatically removed when the component unmounts — no manual removeEventListener needed.