From 114d5ab54155249733940bf27b2db6e8b44c45b3 Mon Sep 17 00:00:00 2001 From: huzibaca Date: Sat, 16 Nov 2024 05:59:01 +0800 Subject: [PATCH] fix: fixes #1940 --- src-tauri/src/core/hotkey.rs | 1 + src/utils/parse-hotkey.ts | 75 +++++++++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/src-tauri/src/core/hotkey.rs b/src-tauri/src/core/hotkey.rs index de2d764c..5ffd0466 100755 --- a/src-tauri/src/core/hotkey.rs +++ b/src-tauri/src/core/hotkey.rs @@ -49,6 +49,7 @@ impl Hotkey { let app_handle = handle::Handle::global().app_handle().unwrap(); let manager = app_handle.global_shortcut(); + dbg!(&hotkey); if manager.is_registered(hotkey) { manager.unregister(hotkey)?; } diff --git a/src/utils/parse-hotkey.ts b/src/utils/parse-hotkey.ts index 864ef4f8..12f96dcf 100644 --- a/src/utils/parse-hotkey.ts +++ b/src/utils/parse-hotkey.ts @@ -1,27 +1,63 @@ const KEY_MAP: Record = { - '"': "'", - ":": ";", - "?": "/", - ">": ".", - "<": ",", - "{": "[", - "}": "]", - "|": "\\", - "!": "1", - "@": "2", - "#": "3", - $: "4", - "%": "5", - "^": "6", - "&": "7", - "*": "8", - "(": "9", - ")": "0", - "~": "`", + // 特殊字符映射 + "-": "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", }; +const mapKeyCombination = (key: string): string => { + const mappedKey = KEY_MAP[key] || key; + return `${mappedKey}`; +}; export const parseHotkey = (key: string) => { let temp = key.toUpperCase(); + console.log(temp); if (temp.startsWith("ARROW")) { temp = temp.slice(5); @@ -34,6 +70,7 @@ export const parseHotkey = (key: string) => { } else if (temp.endsWith("RIGHT")) { temp = temp.slice(0, -5); } + console.log(temp, mapKeyCombination(temp)); switch (temp) { case "CONTROL":