2022-11-23 17:30:19 +08:00
|
|
|
|
const KEY_MAP: Record<string, string> = {
|
2024-11-16 05:59:01 +08:00
|
|
|
|
// 特殊字符映射
|
|
|
|
|
|
"-": "Minus",
|
|
|
|
|
|
"=": "Equal",
|
|
|
|
|
|
"[": "BracketLeft",
|
|
|
|
|
|
"]": "BracketRight",
|
|
|
|
|
|
"\\": "Backslash",
|
|
|
|
|
|
";": "Semicolon",
|
|
|
|
|
|
"'": "Quote",
|
|
|
|
|
|
",": "Comma",
|
|
|
|
|
|
".": "Period",
|
|
|
|
|
|
"/": "Slash",
|
|
|
|
|
|
// Option + 特殊字符映射
|
|
|
|
|
|
"–": "Minus", // Option + -
|
|
|
|
|
|
"≠": "Equal", // Option + =
|
|
|
|
|
|
"\u201C": "BracketLeft", // Option + [
|
|
|
|
|
|
"\u2019": "BracketRight", // Option + ]
|
|
|
|
|
|
"«": "Backslash", // Option + \
|
|
|
|
|
|
"…": "Semicolon", // Option + ;
|
|
|
|
|
|
æ: "Quote", // Option + '
|
|
|
|
|
|
"≤": "Comma", // Option + ,
|
|
|
|
|
|
"≥": "Period", // Option + .
|
|
|
|
|
|
"÷": "Slash", // Option + /
|
|
|
|
|
|
|
|
|
|
|
|
// Option组合键映射
|
|
|
|
|
|
Å: "A",
|
|
|
|
|
|
"∫": "B",
|
|
|
|
|
|
Ç: "C",
|
|
|
|
|
|
"∂": "D",
|
|
|
|
|
|
"´": "E",
|
|
|
|
|
|
ƒ: "F",
|
|
|
|
|
|
"©": "G",
|
|
|
|
|
|
"˙": "H",
|
|
|
|
|
|
ˆ: "I",
|
|
|
|
|
|
"∆": "J",
|
|
|
|
|
|
"˚": "K",
|
|
|
|
|
|
"¬": "L",
|
|
|
|
|
|
µ: "M",
|
|
|
|
|
|
"˜": "N",
|
|
|
|
|
|
Ø: "O",
|
|
|
|
|
|
π: "P",
|
|
|
|
|
|
Œ: "Q",
|
|
|
|
|
|
"®": "R",
|
|
|
|
|
|
ß: "S",
|
|
|
|
|
|
"†": "T",
|
|
|
|
|
|
"¨": "U",
|
|
|
|
|
|
"√": "V",
|
|
|
|
|
|
"∑": "W",
|
|
|
|
|
|
"≈": "X",
|
|
|
|
|
|
"¥": "Y",
|
|
|
|
|
|
Ω: "Z",
|
2022-11-23 17:30:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-11-16 05:59:01 +08:00
|
|
|
|
const mapKeyCombination = (key: string): string => {
|
|
|
|
|
|
const mappedKey = KEY_MAP[key] || key;
|
|
|
|
|
|
return `${mappedKey}`;
|
|
|
|
|
|
};
|
2022-11-23 17:30:19 +08:00
|
|
|
|
export const parseHotkey = (key: string) => {
|
2022-09-18 15:52:53 +08:00
|
|
|
|
let temp = key.toUpperCase();
|
2024-11-16 05:59:01 +08:00
|
|
|
|
console.log(temp);
|
2022-09-18 15:52:53 +08:00
|
|
|
|
|
|
|
|
|
|
if (temp.startsWith("ARROW")) {
|
|
|
|
|
|
temp = temp.slice(5);
|
|
|
|
|
|
} else if (temp.startsWith("DIGIT")) {
|
|
|
|
|
|
temp = temp.slice(5);
|
|
|
|
|
|
} else if (temp.startsWith("KEY")) {
|
|
|
|
|
|
temp = temp.slice(3);
|
|
|
|
|
|
} else if (temp.endsWith("LEFT")) {
|
|
|
|
|
|
temp = temp.slice(0, -4);
|
|
|
|
|
|
} else if (temp.endsWith("RIGHT")) {
|
|
|
|
|
|
temp = temp.slice(0, -5);
|
|
|
|
|
|
}
|
2024-11-16 05:59:01 +08:00
|
|
|
|
console.log(temp, mapKeyCombination(temp));
|
2022-09-18 15:52:53 +08:00
|
|
|
|
|
|
|
|
|
|
switch (temp) {
|
|
|
|
|
|
case "CONTROL":
|
|
|
|
|
|
return "CTRL";
|
|
|
|
|
|
case "META":
|
|
|
|
|
|
return "CMD";
|
|
|
|
|
|
case " ":
|
|
|
|
|
|
return "SPACE";
|
|
|
|
|
|
default:
|
2022-11-23 17:30:19 +08:00
|
|
|
|
return KEY_MAP[temp] || temp;
|
2022-09-18 15:52:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|