Vue3 hooks of Keyboard events
import useHotkey, { HotKey } from 'vue3-hotkey'
import { ref } from 'vue'
setup() {
const hotkeys = ref<HotKey[]>([
{
keys: ['space'],
preventDefault: true,
handler(keys) {
countRef.value += 5
}
},
{
keys: ['shift', 'space'],
preventDefault: true,
handler(keys) {
countRef.value -= 100
}
}
])
const stop = useHotkey(hotkeys.value)
}
npm i vue3-hotkey
or
yarn add vue3-hotkey
This project is heavily inspired by the following awesome projects.
MIT License © 2021-PRESENT caoyugang_1