useKeyPress()
This hook lets you listen for specific key codes and tells you whether they are currently pressed or not.
import { useKeyPress } from '@xyflow/react';
export default function () {
const spacePressed = useKeyPress('Space');
const cmdAndSPressed = useKeyPress(['Meta+s', 'Strg+s']);
return (
<div>
{spacePressed && <p>Space pressed!</p>}
{cmdAndSPressed && <p>Cmd + S pressed!</p>}
</div>
);
}
Signature
Parameters:Notes
- This hook does not rely on a
ReactFlowInstance
so you are free to use it anywhere in your app!
Last updated on