Vue3 hooks of Keyboard input.
pnpm i vue3-hotkey
or
yarn add vue3-hotkey
<script lang="ts" setup>
import useHotkey, { HotKey, RemoveHandler } from 'vue3-hotkey'
import { ref } from 'vue'
const hotkeys = ref<HotKey[]>([
{
keys: ['space'],
preventDefault: true,
handler(keys) {
countRef.value = 5
}
},
{
keys: ['shift', 'space'],
preventDefault: true,
handler(keys) {
countRef.value -= 100
}
}
])
const stopArr = useHotkey(hotkeys.value)
// 取消监听快捷键
const removeHotKeys = (hk: HotKey) => {
stopArr.foreach((item: RemoveHandler) => item())
}
</script>
This project is heavily inspired by the following awesome projects.
MIT License © 2021-PRESENT Talljack