-
-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): optimize hotkey function (#604)
* feat(web): optimize hotkey function
- Loading branch information
Showing
5 changed files
with
127 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
let isff = | ||
typeof navigator !== "undefined" | ||
? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 | ||
: false; // 绑定事件 | ||
let _keyMap: any = { | ||
backspace: 8, | ||
"⌫": 8, | ||
tab: 9, | ||
clear: 12, | ||
enter: 13, | ||
"↩": 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, | ||
num_0: 96, | ||
num_1: 97, | ||
num_2: 98, | ||
num_3: 99, | ||
num_4: 100, | ||
num_5: 101, | ||
num_6: 102, | ||
num_7: 103, | ||
num_8: 104, | ||
num_9: 105, | ||
num_multiply: 106, | ||
num_add: 107, | ||
num_enter: 108, | ||
num_subtract: 109, | ||
num_decimal: 110, | ||
num_divide: 111, | ||
"⇪": 20, | ||
",": 188, | ||
".": 190, | ||
"/": 191, | ||
"`": 192, | ||
"-": isff ? 173 : 189, | ||
"=": isff ? 61 : 187, | ||
";": isff ? 59 : 186, | ||
"'": 222, | ||
"[": 219, | ||
"]": 221, | ||
"\\": 220, | ||
}; // Modifier Keys | ||
|
||
const _modifier: any = { | ||
// shiftKey | ||
"⇧": 16, | ||
shift: 16, | ||
// altKey | ||
"⌥": 18, | ||
alt: 18, | ||
option: 18, | ||
// ctrlKey | ||
"⌃": 17, | ||
ctrl: 17, | ||
control: 17, | ||
// metaKey | ||
"⌘": 91, | ||
cmd: 91, | ||
command: 91, | ||
}; | ||
for (let k = 1; k < 20; k++) { | ||
// F1~F12 special key | ||
_keyMap["f".concat(k.toString())] = 111 + k; | ||
} | ||
|
||
export function stringToCode(x: string) { | ||
return _keyMap[x.toLowerCase()] || _modifier[x.toLowerCase()] || x.toUpperCase().charCodeAt(0); | ||
} | ||
|
||
export function getWhiteList() { | ||
const whiteList = ["s", "r", "p"]; | ||
return whiteList.map((item: string) => stringToCode(item)); | ||
} |