diff --git a/Readme.md b/Readme.md index 222e52c..ed57d01 100644 --- a/Readme.md +++ b/Readme.md @@ -59,6 +59,10 @@ kb.on(['ctrl + c', 'ctrl + v'], ev => { ### API ++ .disabled +> 禁止属性, 允许临时暂时热键. + + + .on(actions``, callback``) > 监听键盘动作组合, 支持单组或双组。 >> 双组时, 2组按键前后时差不能超过`300毫秒`, 否则视为2次独立的操作。 diff --git a/package.json b/package.json index 402d19c..7957467 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,18 @@ { "name": "@bytedo/keyboard", - "version": "1.1.0", + "version": "1.2.0", "description": "支持各种按钮组合。原生js开发, 无任何依赖(不到2KB)。使用也非常简单。", "main": "dist/index.js", "repository": { "type": "git", "url": "git+https://github.com/bytedo/keyboard.git" }, - "keywords": ["keyboard", "hotkey", "shortcut", "yutent"], + "keywords": [ + "keyboard", + "hotkey", + "shortcut", + "yutent" + ], "author": "yutent", "license": "MIT", "dependencies": {} diff --git a/src/index.es7 b/src/index.es7 index 47acd66..8eb8c4c 100644 --- a/src/index.es7 +++ b/src/index.es7 @@ -45,14 +45,20 @@ function check(ev) { export default class Keyboard { constructor(elem) { - console.log(elem) this.$elem = elem hide(this, '__EVENTS__', {}) + hide(this, 'paused', false) hide( this, '_keydown', bind(elem, ev => { + // 允许暂停 + if (this.paused) { + return + } + + // 屏蔽纯辅助键的监听 if (MULTI_KEY_CODES.includes(ev.keyCode)) { return } @@ -74,7 +80,7 @@ export default class Keyboard { if (tmp) { end = true // 第2组一定有回调,无需判断 - next.fn.forEach(function(fn) { + next.fn.forEach(function (fn) { fn(ev) }) break @@ -92,7 +98,7 @@ export default class Keyboard { } // 有回调就触发 if (item.fn) { - item.fn.forEach(function(fn) { + item.fn.forEach(function (fn) { fn(ev) }) } @@ -107,6 +113,14 @@ export default class Keyboard { ) } + get disabled() { + return this.paused + } + + set disabled(v) { + this.paused = !!v + } + destroy() { unbind(this.$elem, this._keydown) delete this.__EVENTS__