From 7c67bb7181fc2b7dbabedb1886b3f3042a8ec4e3 Mon Sep 17 00:00:00 2001 From: Gabe Yuan Date: Fri, 22 Sep 2023 15:33:37 +0800 Subject: [PATCH] change shortcut e.key to e.code --- src/config/i18n.js | 4 ++-- src/config/index.js | 10 +++++----- src/libs/shortcut.js | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/config/i18n.js b/src/config/i18n.js index 7986644..6a1beb8 100644 --- a/src/config/i18n.js +++ b/src/config/i18n.js @@ -576,8 +576,8 @@ export const I18N = { en: `Trigger Translation Shortcut Keys`, }, trigger_trans_shortcut_help: { - zh: `默认为单击“Alt+i”`, - en: `Default is "Alt+i"`, + zh: `默认为单击“AltLeft+KeyI”`, + en: `Default is "AltLeft+KeyI"`, }, shortcut_press_count: { zh: `快捷键连击次数`, diff --git a/src/config/index.js b/src/config/index.js index cd66c27..9fb2e61 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -201,7 +201,7 @@ export const GLOBLA_RULE = { // 输入框翻译 export const OPT_INPUT_TRANS_SIGNS = ["/", "//", "\\", "\\\\", ">", ">>"]; -export const DEFAULT_INPUT_SHORTCUT = ["Alt", "i"]; +export const DEFAULT_INPUT_SHORTCUT = ["AltLeft", "KeyI"]; export const DEFAULT_INPUT_RULE = { transOpen: true, translator: OPT_TRANS_MICROSOFT, @@ -261,10 +261,10 @@ export const OPT_SHORTCUT_STYLE = "toggleStyle"; export const OPT_SHORTCUT_POPUP = "togglePopup"; export const OPT_SHORTCUT_SETTING = "openSetting"; export const DEFAULT_SHORTCUTS = { - [OPT_SHORTCUT_TRANSLATE]: ["Alt", "q"], - [OPT_SHORTCUT_STYLE]: ["Alt", "c"], - [OPT_SHORTCUT_POPUP]: ["Alt", "k"], - [OPT_SHORTCUT_SETTING]: ["Alt", "o"], + [OPT_SHORTCUT_TRANSLATE]: ["AltLeft", "KeyQ"], + [OPT_SHORTCUT_STYLE]: ["AltLeft", "KeyC"], + [OPT_SHORTCUT_POPUP]: ["AltLeft", "KeyK"], + [OPT_SHORTCUT_SETTING]: ["AltLeft", "KeyN"], }; export const TRANS_MIN_LENGTH = 5; // 最短翻译长度 diff --git a/src/libs/shortcut.js b/src/libs/shortcut.js index 4d48603..0bd8d49 100644 --- a/src/libs/shortcut.js +++ b/src/libs/shortcut.js @@ -22,14 +22,14 @@ export const shortcutListener = (fn, target = document, timeout = 3000) => { }, timeout); if (e.code) { - allkeys.add(e.key); - curkeys.add(e.key); + allkeys.add(e.code); + curkeys.add(e.code); fn([...curkeys], [...allkeys]); } }; const handleKeyup = (e) => { - curkeys.delete(e.key); + curkeys.delete(e.code); if (curkeys.size === 0) { fn([...curkeys], [...allkeys]); allkeys.clear();