vue3-hotkey
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

vue3-hotKey

Vue3 hooks of Keyboard input.

📦 Install

pnpm i vue3-hotkey

or

yarn add vue3-hotkey

🦄 Usage

import useHotkey, { HotKey, RemoveHandler } 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 stopArr = useHotkey(hotkeys.value)

  // 取消监听快捷键
  const removeHotKeys = (hk: HotKey) => {
    stopArr.foreach((item: RemoveHandler) => item())
  }
}

🌸 Thanks

This project is heavily inspired by the following awesome projects.

📄 License

MIT License © 2021-PRESENT Talljack

🍺 Sponsor

如果大家喜欢我的项目的话,可以请我喝杯咖啡哦,谢谢!

/vue3-hotkey/

    Package Sidebar

    Install

    npm i vue3-hotkey

    Weekly Downloads

    709

    Version

    1.0.6

    License

    MIT

    Unpacked Size

    21 kB

    Total Files

    23

    Last publish

    Collaborators

    • caoyugang