Skip to content

Commit

Permalink
Fix custom keyboard shortcut issues caused by system keyboard shortcu…
Browse files Browse the repository at this point in the history
…ts. #86
  • Loading branch information
jaywcjlove committed May 27, 2019
1 parent 7478030 commit edf976c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -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 = []; // 已绑定事件的节点记录
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/var.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const _modifier = { // 修饰键
cmd: isff ? 224 : 91,
command: isff ? 224 : 91,
};
const _downKeys = []; // 记录摁下的绑定键
const modifierMap = {
16: 'shiftKey',
18: 'altKey',
Expand All @@ -70,7 +69,6 @@ _mods[isff ? 224 : 91] = false;
export {
_keyMap,
_modifier,
_downKeys,
modifierMap,
_mods,
_handlers,
Expand Down

0 comments on commit edf976c

Please sign in to comment.