useKeyPress()
The useKeyPress composable returns a reactive boolean that tracks whether a given key or
key combination is currently pressed. It is the same key-filter mechanism Vue Flow
uses internally for shortcuts like selection and deletion.
<script setup lang="ts">
import { useKeyPress } from '@xyflow/vue';
const shiftPressed = useKeyPress('Shift');
const saveCombo = useKeyPress(['Meta+s', 'Control+s']);
</script>Signature
Parameters:Notes
- The key filter accepts a single key, an array of keys/combinations, a boolean, or
null— and can be a ref or getter so it stays reactive. - Options let you scope the listener to a target element, react to combinations while
typing in inputs, and control
preventDefault.