https://github.com/imcuttle/is-hotkey-combine
The shortest way to check multi-times keydown
https://github.com/imcuttle/is-hotkey-combine
Last synced: 4 months ago
JSON representation
The shortest way to check multi-times keydown
- Host: GitHub
- URL: https://github.com/imcuttle/is-hotkey-combine
- Owner: imcuttle
- License: mit
- Created: 2020-02-04T06:27:33.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T06:25:06.000Z (over 3 years ago)
- Last Synced: 2025-08-01T02:59:25.254Z (11 months ago)
- Language: JavaScript
- Size: 1.2 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: License
Awesome Lists containing this project
README
# is-hotkey-combine
[](https://travis-ci.org/imcuttle/is-hotkey-combine)
[](https://codecov.io/github/imcuttle/is-hotkey-combine?branch=master)
[](https://www.npmjs.com/package/is-hotkey-combine)
[](https://www.npmjs.com/package/is-hotkey-combine)
[](https://prettier.io/)
[](https://conventionalcommits.org)
> The shortest way to check multi-times keydown
Inspired by [is-hotkey](https://github.com/ianstormtaylor/is-hotkey#readme)
## Installation
```bash
npm install is-hotkey-combine
# or use yarn
yarn add is-hotkey-combine
```
## Usage
```javascript
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](https://github.com/ianstormtaylor/is-hotkey#readme)
## 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](https://github.com/imcuttle) 🐟