Skip to Content
⭐️ Leave a star →
HooksuseHotkeys

useHotkeys

Binds keyboard shortcuts to handlers. Combos use a familiar string syntax: mod+k resolves to ⌘K on macOS and Ctrl+K elsewhere; shift+/ covers ?; + separates modifiers from the key.

By default shortcuts don’t fire while the user is typing inside an <input>, <textarea>, or [contenteditable] element — opt back in per binding with enableOnFormTags.

import { useHotkeys } from '@wire-ui/react' function CommandPalette({ open, onOpen, onClose }) { useHotkeys({ 'mod+k': (e) => { e.preventDefault() onOpen() }, 'escape': () => onClose(), }) return open ? <Palette /> : null }

Scopes

Use scope + activeScopes to isolate a binding to a particular UI surface (e.g. shortcuts that only fire while a modal is open). Bindings with scope: '*' always fire.

useHotkeys( { 'enter': onSubmit }, { scope: 'dialog', activeScopes: isOpen ? ['dialog'] : [] }, )

Parameters

ParamTypeDescription
mapRecord<string, (event: KeyboardEvent) => void>Combo → handler.
optionsUseHotkeysOptionsSee below.

Options

OptionTypeDefaultDescription
targetRefObject | HTMLElement | Window | Document | nullwindowWhere to attach the listener.
event'keydown' | 'keyup''keydown'Which keyboard event fires the handler.
enabledbooleantrueGlobally toggle all bindings.
scopestring'*'Scope name this binding belongs to.
activeScopesstring[][]Scopes currently active. Bindings with scope: '*' ignore this.
enableInInputsbooleanfalseAllow bindings to fire while typing in input / textarea / contenteditable.
preventDefaultbooleanfalseCall event.preventDefault() on every match.
Last updated on

MIT License © 2026 wire-ui

useHotkeys – Wire UI