You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.1 KiB
JavaScript
76 lines
1.1 KiB
JavaScript
import { isff } from './utils';
|
|
|
|
const _keyMap = { // 特殊键
|
|
backspace: 8,
|
|
tab: 9,
|
|
clear: 12,
|
|
enter: 13,
|
|
return: 13,
|
|
esc: 27,
|
|
escape: 27,
|
|
space: 32,
|
|
left: 37,
|
|
up: 38,
|
|
right: 39,
|
|
down: 40,
|
|
del: 46,
|
|
delete: 46,
|
|
ins: 45,
|
|
insert: 45,
|
|
home: 36,
|
|
end: 35,
|
|
pageup: 33,
|
|
pagedown: 34,
|
|
capslock: 20,
|
|
'⇪': 20,
|
|
',': 188,
|
|
'.': 190,
|
|
'/': 191,
|
|
'`': 192,
|
|
'-': isff ? 173 : 189,
|
|
'=': isff ? 61 : 187,
|
|
';': isff ? 59 : 186,
|
|
'\'': 222,
|
|
'[': 219,
|
|
']': 221,
|
|
'\\': 220,
|
|
};
|
|
|
|
const _modifier = { // 修饰键
|
|
'⇧': 16,
|
|
shift: 16,
|
|
'⌥': 18,
|
|
alt: 18,
|
|
option: 18,
|
|
'⌃': 17,
|
|
ctrl: 17,
|
|
control: 17,
|
|
'⌘': isff ? 224 : 91,
|
|
cmd: isff ? 224 : 91,
|
|
command: isff ? 224 : 91,
|
|
};
|
|
const modifierMap = {
|
|
16: 'shiftKey',
|
|
18: 'altKey',
|
|
17: 'ctrlKey',
|
|
};
|
|
const _mods = { 16: false, 18: false, 17: false };
|
|
const _handlers = {};
|
|
|
|
// F1~F12 特殊键
|
|
for (let k = 1; k < 20; k++) {
|
|
_keyMap[`f${k}`] = 111 + k;
|
|
}
|
|
|
|
// 兼容Firefox处理
|
|
modifierMap[isff ? 224 : 91] = 'metaKey';
|
|
_mods[isff ? 224 : 91] = false;
|
|
|
|
export {
|
|
_keyMap,
|
|
_modifier,
|
|
modifierMap,
|
|
_mods,
|
|
_handlers,
|
|
};
|