Skip to content

useKeyPress

useKeyPress(keyCode, options?): boolean

Tracks whether a given key (or key combo) is currently held down.

Defaults to firing only when the diagram canvas (body / .react-flow__*) has focus — text inputs are excluded so typing in a property field doesn’t accidentally trigger keyboard shortcuts. Pass skipTarget: true to listen globally and withControlOrMeta: true to require Ctrl / Cmd to also be down.

KeyCode

xyflow KeyCode (single key string or combo).

Options

Optional skipTarget / withControlOrMeta flags.

boolean

true while the key is pressed; false otherwise.