From edf976c4bca2b8f3e0b0a2570677acf1265404e0 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Mon, 27 May 2019 23:24:35 +0800 Subject: [PATCH] Fix custom keyboard shortcut issues caused by system keyboard shortcuts. #86 --- src/main.js | 8 ++++++-- src/var.js | 2 -- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.js b/src/main.js index 9a0718d1..e6f2f65f 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,7 @@ import { addEvent, getMods, getKeys, compareArray } from './utils'; -import { _keyMap, _modifier, _downKeys, modifierMap, _mods, _handlers } from './var'; +import { _keyMap, _modifier, modifierMap, _mods, _handlers } from './var'; +let _downKeys = []; // 记录摁下的绑定键 let _scope = 'all'; // 默认热键范围 const elementHasBindEvent = []; // 已绑定事件的节点记录 @@ -296,11 +297,14 @@ function hotkeys(key, option, method) { }); } // 在全局document上设置快捷键 - if (typeof element !== 'undefined' && !isElementBind(element)) { + if (typeof element !== 'undefined' && !isElementBind(element) && window) { elementHasBindEvent.push(element); addEvent(element, 'keydown', (e) => { dispatch(e); }); + addEvent(window, 'focus', () => { + _downKeys = []; + }); addEvent(element, 'keyup', (e) => { dispatch(e); clearModifier(e); diff --git a/src/var.js b/src/var.js index 6645aa9c..f1f7acb9 100644 --- a/src/var.js +++ b/src/var.js @@ -49,7 +49,6 @@ const _modifier = { // 修饰键 cmd: isff ? 224 : 91, command: isff ? 224 : 91, }; -const _downKeys = []; // 记录摁下的绑定键 const modifierMap = { 16: 'shiftKey', 18: 'altKey', @@ -70,7 +69,6 @@ _mods[isff ? 224 : 91] = false; export { _keyMap, _modifier, - _downKeys, modifierMap, _mods, _handlers,