perf: 优化 ctrl 监听

This commit is contained in:
奔跑的面条
2022-10-10 18:47:07 +08:00
parent 293259a97d
commit af1c280f28
5 changed files with 14 additions and 33 deletions
+7 -6
View File
@@ -107,16 +107,17 @@ const macKeyList: Array<string> = [
// 处理键盘记录
const keyRecordHandle = () => {
// 初始化清空
if(window.$KeyboardActive) window.$KeyboardActive = new Set([])
// 默认赋值
window.$KeyboardActive = {
ctrl: true
}
document.onkeydown = (e: KeyboardEvent) => {
if(window.$KeyboardActive) window.$KeyboardActive.add(e.key.toLocaleLowerCase())
else window.$KeyboardActive = new Set([e.key.toLocaleLowerCase()])
if(e.keyCode === 17 && window.$KeyboardActive) window.$KeyboardActive.ctrl = true
}
document.onkeyup = (e: KeyboardEvent) => {
if(window.$KeyboardActive) window.$KeyboardActive.delete(e.key.toLocaleLowerCase())
if(e.keyCode === 17 && window.$KeyboardActive) window.$KeyboardActive.ctrl = false
}
}