keydown event
The browser event fired when a key is pressed, whose key property names the key, such as "Escape" or "ArrowDown".
In more detail
A useKeyPress hook listens for keydown on window and runs a callback when event.key matches. Keyboard navigation in menus and tabs also relies on it.
Example
A useKeyPress hook listens for keydown on window and runs a callback when event.key matches.Related terms
- event listener — A function registered with addEventListener that the browser calls whenever a given event happens on an element or on window.
- keyboard navigation — Using a page entirely with the keyboard: Tab to move between controls, Enter and Space to activate, arrow keys inside widgets, Escape to close.
Taught in
- Focus Management: Trapping, Restoration & Focus Rings — Design Systems & Component Engineering
- Keyboard Navigation Protocols: Roving Tabindex & Virtual Focus — Design Systems & Component Engineering
- Creating Event Listener Hooks with Clean Teardown Logic — React 19 & Modern Component Architecture
- Concurrent Mode: Interruptible Work And Lane Priority — React 19 & Modern Component Architecture
- useTransition: Non-Blocking State Updates for Fluid UI — React 19 & Modern Component Architecture
- Render Diagnostics: Profiling Re-Renders with React DevTools — React 19 & Modern Component Architecture