TanStack Hotkeys provides the useHotkeyRecorder composable for building shortcut customization UIs in Vue.
<script setup lang="ts">
import { formatForDisplay, useHotkeyRecorder } from '@tanstack/vue-hotkeys'
const recorder = useHotkeyRecorder({
onRecord: (hotkey) => {
console.log('Recorded:', hotkey)
},
})
</script>
<template>
<div>
<button @click="recorder.isRecording ? recorder.stopRecording() : recorder.startRecording()">
{{
recorder.isRecording
? 'Press a key combination...'
: recorder.recordedHotkey
? formatForDisplay(recorder.recordedHotkey)
: 'Click to record'
}}
</button>
<button v-if="recorder.isRecording" @click="recorder.cancelRecording()">
Cancel
</button>
</div>
</template>
useHotkeyRecorder({
onRecord: (hotkey) => {},
onCancel: () => {},
onClear: () => {},
})
<script setup lang="ts">
import { HotkeysProvider } from '@tanstack/vue-hotkeys'
</script>
<template>
<HotkeysProvider
:default-options="{
hotkeyRecorder: {
onCancel: () => console.log('Recording cancelled'),
},
}"
>
<AppContent />
</HotkeysProvider>
</template>