is-hotkey-combine

1.0.1 • Public • Published

is-hotkey-combine

Build status Test coverage NPM version NPM Downloads Prettier Conventional Commits

The shortest way to check multi-times keydown

Inspired by is-hotkey

Installation

npm install is-hotkey-combine
# or use yarn 
yarn add is-hotkey-combine

Usage

import isHotkeyCombine from 'is-hotkey-combine'
 
document.addEventListener('keydown', evt => {
  if (isHotkeyCombine('shift*2', evt /*, options */)) {
    // trigger when pressing `shift` twice
  }
  
  if (isHotkeyCombine('shift+a->b', evt /*, options */)) {
    // trigger when pressing `shift+a` and `b` quickly
  }
 
  if (isHotkeyCombine(['shift+a', 'b'], evt /*, options */)) {
    // trigger when pressing `shift+a` and `b` quickly
  }
})

API

isHotkeyCombine(hotKey: string|string[], event: Event, options): boolean

Options

duration

The duration about nearby trigger.

  • Type: number
  • Default: 250

byKey

Extends from is-hotkey

Contributing

  • Fork it!
  • Create your new branch:
    git checkout -b feature-new or git checkout -b fix-which-bug
  • Start your magic work now
  • Make sure npm test passes
  • Commit your changes:
    git commit -am 'feat: some description (close #123)' or git commit -am 'fix: some description (fix #123)'
  • Push to the branch: git push
  • Submit a pull request :)

Authors

This library is written and maintained by imcuttle, moyuyc95@gmail.com.

License

MIT - imcuttle 🐟

/is-hotkey-combine/

    Package Sidebar

    Install

    npm i is-hotkey-combine

    Weekly Downloads

    3

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    27.5 kB

    Total Files

    16

    Last publish

    Collaborators

    • moyuyc