优化按键判断

master
宇天 2020-11-06 09:46:36 +08:00
parent f1e63fe545
commit 0ea3d62a33
2 changed files with 20 additions and 16 deletions

View File

@ -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": {}

View File

@ -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
}
}
}
@ -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('+'))
})