From 0ea3d62a335d41d2e4ea946cc7c8406781dac903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Fri, 6 Nov 2020 09:46:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8C=89=E9=94=AE=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 9 ++------- src/index.es7 | 27 ++++++++++++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 7957467..3c3578b 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,13 @@ { "name": "@bytedo/keyboard", - "version": "1.2.0", + "version": "1.2.1", "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 8eb8c4c..ba33d7c 100644 --- a/src/index.es7 +++ b/src/index.es7 @@ -35,8 +35,11 @@ function check(ev) { } if (checked) { - for (let k of this.keys) { - checked = ev[`${k}Key`] + for (let k in this.keys) { + if (ev[k] !== this.keys[k]) { + checked = false + break + } } } @@ -80,7 +83,7 @@ export default class Keyboard { if (tmp) { end = true // 第2组一定有回调,无需判断 - next.fn.forEach(function (fn) { + next.fn.forEach(function(fn) { fn(ev) }) break @@ -98,7 +101,7 @@ export default class Keyboard { } // 有回调就触发 if (item.fn) { - item.fn.forEach(function (fn) { + item.fn.forEach(function(fn) { fn(ev) }) } @@ -133,27 +136,33 @@ export default class Keyboard { var passed = true // 语法检测通过 act.forEach(it => { - var tmp = [] - dict.push(tmp) + var tmp = {} + it = it.split('+').map(k => { k = k.trim().toLowerCase() if (MULTI_KEYS[k]) { - if (tmp.includes(k)) { + if (tmp[`${k}Key`]) { passed = false console.error('功能键,同组中不能重复。⎣%s⎤', it) } else { - tmp.push(k) + tmp[`${k}Key`] = true } } else { if (tmp.key) { passed = false console.error('非功能键,同组不能出现多个。⎣%s⎤', it) } else { - tmp.key = KEY_DICT[k] + hide(tmp, 'key', KEY_DICT[k]) } } return k }) + + for (let k in MULTI_KEYS) { + tmp[`${k}Key`] = tmp[`${k}Key`] || false + } + + dict.push(tmp) keys.push(it.join('+')) })