Fix custom keyboard shortcut issues caused by system keyboard shortcuts. #86

pull/93/head
jaywcjlove 6 years ago
parent 747803040d
commit edf976c4bc

@ -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);

@ -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,

Loading…
Cancel
Save