From 69218a728b34005bdd573e5171d7b1b13b55c796 Mon Sep 17 00:00:00 2001 From: lanxiuyun <212650356+lanxiuyun@users.noreply.github.com> Date: Tue, 10 Jun 2025 10:25:25 +0800 Subject: [PATCH 1/9] Update index.vue --- feature/src/views/settings/index.vue | 48 ++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/feature/src/views/settings/index.vue b/feature/src/views/settings/index.vue index 9cdfda3..2205f60 100644 --- a/feature/src/views/settings/index.vue +++ b/feature/src/views/settings/index.vue @@ -274,12 +274,16 @@ const state = reactive({ custom: {}, }); +// 添加lastKeyPressTime变量来跟踪按键时间 +const lastKeyPressTime = ref(0); +const DOUBLE_CLICK_THRESHOLD = 300; // 双击时间阈值(毫秒) + const isWindows = window?.rubick?.isWindows(); const tipText = computed(() => { const optionKeyName = isWindows ? 'Alt' : 'Option、Command'; return t('feature.settings.global.addShortcutKeyTips', { optionKeyName: optionKeyName, - }); + }) + `此外你也可以双击修饰键,如(Ctrl+Ctrl)`; }); const currentSelect = ref(['userInfo']); @@ -316,6 +320,34 @@ const changeShortCut = (e, key) => { let compose = ''; // 添加是否包含功能键的判断 let incluFuncKeys = false; + const currentTime = Date.now(); + const isDoubleClick = + currentTime - lastKeyPressTime.value < DOUBLE_CLICK_THRESHOLD; + lastKeyPressTime.value = currentTime; + + // 检查是否是修饰键的双击 + if (e.keyCode === 17 && isDoubleClick) { + // Ctrl + state.shortCut[key] = 'Ctrl+Ctrl'; + return; + } + if (e.keyCode === 18 && isDoubleClick) { + // Alt + state.shortCut[key] = 'Option+Option'; + return; + } + if (e.keyCode === 16 && isDoubleClick) { + // Shift + state.shortCut[key] = 'Shift+Shift'; + return; + } + if (e.keyCode === 93 && isDoubleClick) { + // Command + state.shortCut[key] = 'Command+Command'; + return; + } + + // 处理修饰键+普通键的组合 if (e.ctrlKey && e.keyCode !== 17) { compose += '+Ctrl'; incluFuncKeys = true; @@ -332,15 +364,11 @@ const changeShortCut = (e, key) => { compose += '+Command'; incluFuncKeys = true; } - compose += '+' + keycodes[e.keyCode].toUpperCase(); - compose = compose.substring(1); - if ( - incluFuncKeys && - e.keyCode !== 16 && - e.keyCode !== 17 && - e.keyCode !== 18 && - e.keyCode !== 93 - ) { + + // 只有当有修饰键时才添加普通键 + if (incluFuncKeys) { + compose += '+' + keycodes[e.keyCode].toUpperCase(); + compose = compose.substring(1); state.shortCut[key] = compose; } else { // 不做处理 From d41caa742b5e6135227f8659db218b138e91e987 Mon Sep 17 00:00:00 2001 From: lanxiuyun <212650356+lanxiuyun@users.noreply.github.com> Date: Tue, 10 Jun 2025 10:39:44 +0800 Subject: [PATCH 2/9] Update index.vue --- feature/src/views/settings/index.vue | 61 +++++++++++++++------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/feature/src/views/settings/index.vue b/feature/src/views/settings/index.vue index 2205f60..5b51717 100644 --- a/feature/src/views/settings/index.vue +++ b/feature/src/views/settings/index.vue @@ -318,55 +318,58 @@ watch(state, setConfig); const changeShortCut = (e, key) => { let compose = ''; - // 添加是否包含功能键的判断 - let incluFuncKeys = false; const currentTime = Date.now(); - const isDoubleClick = - currentTime - lastKeyPressTime.value < DOUBLE_CLICK_THRESHOLD; + const isDoubleClick = currentTime - lastKeyPressTime.value < DOUBLE_CLICK_THRESHOLD; lastKeyPressTime.value = currentTime; - // 检查是否是修饰键的双击 - if (e.keyCode === 17 && isDoubleClick) { - // Ctrl - state.shortCut[key] = 'Ctrl+Ctrl'; - return; - } - if (e.keyCode === 18 && isDoubleClick) { - // Alt - state.shortCut[key] = 'Option+Option'; - return; - } - if (e.keyCode === 16 && isDoubleClick) { - // Shift - state.shortCut[key] = 'Shift+Shift'; - return; - } - if (e.keyCode === 93 && isDoubleClick) { - // Command - state.shortCut[key] = 'Command+Command'; + // 处理 F1-F12 功能键 + if (e.keyCode >= 112 && e.keyCode <= 123) { + state.shortCut[key] = keycodes[e.keyCode].toUpperCase(); return; } - // 处理修饰键+普通键的组合 + // 处理双击功能键的情况 + if (isDoubleClick) { + if (e.keyCode === 17) { // Ctrl + state.shortCut[key] = 'Ctrl+Ctrl'; + return; + } + if (e.keyCode === 18) { // Alt + state.shortCut[key] = 'Option+Option'; + return; + } + if (e.keyCode === 16) { // Shift + state.shortCut[key] = 'Shift+Shift'; + return; + } + if (e.keyCode === 93) { // Command + state.shortCut[key] = 'Command+Command'; + return; + } + } + + // 处理功能键+普通键的组合 + let hasModifierKey = false; + if (e.ctrlKey && e.keyCode !== 17) { compose += '+Ctrl'; - incluFuncKeys = true; + hasModifierKey = true; } if (e.shiftKey && e.keyCode !== 16) { compose += '+Shift'; - incluFuncKeys = true; + hasModifierKey = true; } if (e.altKey && e.keyCode !== 18) { compose += '+Option'; - incluFuncKeys = true; + hasModifierKey = true; } if (e.metaKey && e.keyCode !== 93) { compose += '+Command'; - incluFuncKeys = true; + hasModifierKey = true; } // 只有当有修饰键时才添加普通键 - if (incluFuncKeys) { + if (hasModifierKey) { compose += '+' + keycodes[e.keyCode].toUpperCase(); compose = compose.substring(1); state.shortCut[key] = compose; From 481cd44ab3c4ced9e3ad9f6fbad40c1bc43f16e7 Mon Sep 17 00:00:00 2001 From: lanxiuyun <212650356+lanxiuyun@users.noreply.github.com> Date: Tue, 10 Jun 2025 10:53:13 +0800 Subject: [PATCH 3/9] Update registerHotKey.ts --- src/main/common/registerHotKey.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/common/registerHotKey.ts b/src/main/common/registerHotKey.ts index 782787f..b4f3923 100644 --- a/src/main/common/registerHotKey.ts +++ b/src/main/common/registerHotKey.ts @@ -63,8 +63,10 @@ const registerHotKey = (mainWindow: BrowserWindow): void => { await setTheme(); const config = await localConfig.getConfig(); globalShortcut.unregisterAll(); + // 注册偏好快捷键 - globalShortcut.register(config.perf.shortCut.showAndHidden, () => { + // 显示/隐藏快捷键 + function mainWindowPopUp() { const currentShow = mainWindow.isVisible() && mainWindow.isFocused(); if (currentShow) return mainWindow.hide(); const { x: wx, y: wy } = winPosition.getPosition(); @@ -76,8 +78,33 @@ const registerHotKey = (mainWindow: BrowserWindow): void => { }); mainWindow.setPosition(wx, wy); mainWindow.show(); - }); + } + let lastModifierPress = 0; + if ( + config.perf.shortCut.showAndHidden == 'Ctrl+Ctrl' || + config.perf.shortCut.showAndHidden == 'Option+Option' || + config.perf.shortCut.showAndHidden == 'Shift+Shift' || + config.perf.shortCut.showAndHidden == 'Command+Command' + ) { + // 双击快捷键,如 Ctrl+Ctrl + const modifers = config.perf.shortCut.showAndHidden.split('+'); + const key = modifers.pop(); + globalShortcut.register(key, () => { + const currentTime = Date.now(); + if (currentTime - lastModifierPress < 300) { + mainWindowPopUp(); + } + lastModifierPress = currentTime; + }); + } else { + // 普通快捷键,如 Ctrl+Space + globalShortcut.register(config.perf.shortCut.showAndHidden, () => + mainWindowPopUp() + ); + } + + // 截图快捷键 globalShortcut.register(config.perf.shortCut.capture, () => { screenCapture(mainWindow, (data) => { data && From 1e7a8209b778e51ca5b05ee3440f8ce8ef36587d Mon Sep 17 00:00:00 2001 From: lanxiuyun <212650356+lanxiuyun@users.noreply.github.com> Date: Tue, 10 Jun 2025 14:14:37 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8F=8C=E5=87=BB?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/common/registerHotKey.ts | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/common/registerHotKey.ts b/src/main/common/registerHotKey.ts index b4f3923..f4b8cc9 100644 --- a/src/main/common/registerHotKey.ts +++ b/src/main/common/registerHotKey.ts @@ -10,6 +10,7 @@ import { import screenCapture from '@/core/screen-capture'; import localConfig from '@/main/common/initLocalConfig'; import winPosition from './getWinPosition'; +import { uIOhook, UiohookKey } from 'uiohook-napi'; const registerHotKey = (mainWindow: BrowserWindow): void => { // 设置开机启动 @@ -80,7 +81,7 @@ const registerHotKey = (mainWindow: BrowserWindow): void => { mainWindow.show(); } - let lastModifierPress = 0; + let lastModifierPress = Date.now(); if ( config.perf.shortCut.showAndHidden == 'Ctrl+Ctrl' || config.perf.shortCut.showAndHidden == 'Option+Option' || @@ -88,15 +89,27 @@ const registerHotKey = (mainWindow: BrowserWindow): void => { config.perf.shortCut.showAndHidden == 'Command+Command' ) { // 双击快捷键,如 Ctrl+Ctrl + uIOhook.stop(); const modifers = config.perf.shortCut.showAndHidden.split('+'); - const key = modifers.pop(); - globalShortcut.register(key, () => { - const currentTime = Date.now(); - if (currentTime - lastModifierPress < 300) { - mainWindowPopUp(); + const showAndHiddenKey = modifers.pop(); + const key2uioKeyCode = { + Ctrl: UiohookKey.Ctrl, + Shift: UiohookKey.Shift, + Alt: UiohookKey.Alt, + Comma: UiohookKey.Comma, + }; + + uIOhook.on('keydown', (e) => { + if (e.keycode === key2uioKeyCode[showAndHiddenKey]) { + const currentTime = Date.now(); + if (currentTime - lastModifierPress < 300) { + mainWindowPopUp(); + } + lastModifierPress = currentTime; } - lastModifierPress = currentTime; }); + + uIOhook.start(); } else { // 普通快捷键,如 Ctrl+Space globalShortcut.register(config.perf.shortCut.showAndHidden, () => From e9c41b6bdb2f0a0ba8c89f2801f7e6809909b6b3 Mon Sep 17 00:00:00 2001 From: lanxiuyun <212650356+lanxiuyun@users.noreply.github.com> Date: Tue, 10 Jun 2025 14:23:51 +0800 Subject: [PATCH 5/9] Update index.vue --- feature/src/views/settings/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feature/src/views/settings/index.vue b/feature/src/views/settings/index.vue index 5b51717..8efbed9 100644 --- a/feature/src/views/settings/index.vue +++ b/feature/src/views/settings/index.vue @@ -283,7 +283,7 @@ const tipText = computed(() => { const optionKeyName = isWindows ? 'Alt' : 'Option、Command'; return t('feature.settings.global.addShortcutKeyTips', { optionKeyName: optionKeyName, - }) + `此外你也可以双击修饰键,如(Ctrl+Ctrl)`; + }) + `此外你也可以双击修饰键如(Ctrl+Ctrl, 双击修饰键需要重启)`; }); const currentSelect = ref(['userInfo']); From 599538db76dd8baf59138a513f121e76fb25c0f5 Mon Sep 17 00:00:00 2001 From: lanxiuyun <212650356+lanxiuyun@users.noreply.github.com> Date: Tue, 10 Jun 2025 14:33:16 +0800 Subject: [PATCH 6/9] Update package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 46a0f7a..2fd5921 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "pouchdb-load": "^1.4.6", "pouchdb-replication-stream": "^1.2.9", "simple-plist": "0.2.1", + "uiohook-napi": "^1.5.4", "vue": "^3.0.0", "vue-router": "^4.0.0-0", "vuex": "^4.0.0-0", From e90a30c8a4e5b4cc601f0c4b6e85f637d1793bd1 Mon Sep 17 00:00:00 2001 From: lanxiuyun <212650356+lanxiuyun@users.noreply.github.com> Date: Thu, 12 Jun 2025 15:04:10 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E4=BC=98=E5=8C=96=20uIOhook=20=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/common/registerHotKey.ts | 100 +++++++++++++++++------------- 1 file changed, 58 insertions(+), 42 deletions(-) diff --git a/src/main/common/registerHotKey.ts b/src/main/common/registerHotKey.ts index f4b8cc9..22d776f 100644 --- a/src/main/common/registerHotKey.ts +++ b/src/main/common/registerHotKey.ts @@ -58,6 +58,20 @@ const registerHotKey = (mainWindow: BrowserWindow): void => { } }; + function mainWindowPopUp() { + const currentShow = mainWindow.isVisible() && mainWindow.isFocused(); + if (currentShow) return mainWindow.hide(); + const { x: wx, y: wy } = winPosition.getPosition(); + mainWindow.setAlwaysOnTop(false); + mainWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true }); + mainWindow.focus(); + mainWindow.setVisibleOnAllWorkspaces(false, { + visibleOnFullScreen: true, + }); + mainWindow.setPosition(wx, wy); + mainWindow.show(); + } + const init = async () => { await setAutoLogin(); await setDarkMode(); @@ -67,51 +81,14 @@ const registerHotKey = (mainWindow: BrowserWindow): void => { // 注册偏好快捷键 // 显示/隐藏快捷键 - function mainWindowPopUp() { - const currentShow = mainWindow.isVisible() && mainWindow.isFocused(); - if (currentShow) return mainWindow.hide(); - const { x: wx, y: wy } = winPosition.getPosition(); - mainWindow.setAlwaysOnTop(false); - mainWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true }); - mainWindow.focus(); - mainWindow.setVisibleOnAllWorkspaces(false, { - visibleOnFullScreen: true, - }); - mainWindow.setPosition(wx, wy); - mainWindow.show(); - } - - let lastModifierPress = Date.now(); if ( - config.perf.shortCut.showAndHidden == 'Ctrl+Ctrl' || - config.perf.shortCut.showAndHidden == 'Option+Option' || - config.perf.shortCut.showAndHidden == 'Shift+Shift' || - config.perf.shortCut.showAndHidden == 'Command+Command' + ['Ctrl+Ctrl', 'Option+Option', 'Shift+Shift', 'Command+Command'].includes( + config.perf.shortCut.showAndHidden + ) ) { - // 双击快捷键,如 Ctrl+Ctrl - uIOhook.stop(); - const modifers = config.perf.shortCut.showAndHidden.split('+'); - const showAndHiddenKey = modifers.pop(); - const key2uioKeyCode = { - Ctrl: UiohookKey.Ctrl, - Shift: UiohookKey.Shift, - Alt: UiohookKey.Alt, - Comma: UiohookKey.Comma, - }; - - uIOhook.on('keydown', (e) => { - if (e.keycode === key2uioKeyCode[showAndHiddenKey]) { - const currentTime = Date.now(); - if (currentTime - lastModifierPress < 300) { - mainWindowPopUp(); - } - lastModifierPress = currentTime; - } - }); - - uIOhook.start(); + // 双击快捷键,详见 uIOhookRegister } else { - // 普通快捷键,如 Ctrl+Space + // 普通快捷键,如 Ctrl+Space,F8 globalShortcut.register(config.perf.shortCut.showAndHidden, () => mainWindowPopUp() ); @@ -141,9 +118,48 @@ const registerHotKey = (mainWindow: BrowserWindow): void => { }); }); }; + + uIOhookRegister(mainWindowPopUp); init(); ipcMain.on('re-register', () => { init(); }); }; export default registerHotKey; + +function uIOhookRegister(callback: () => void) { + let lastModifierPress = Date.now(); + uIOhook.on('keydown', async (uio_event) => { + const config = await localConfig.getConfig(); // 此处还有优化空间 + + if ( + ![ + 'Ctrl+Ctrl', + 'Option+Option', + 'Shift+Shift', + 'Command+Command', + ].includes(config.perf.shortCut.showAndHidden) + ) { + return; + } + + // 双击快捷键,如 Ctrl+Ctrl + const modifers = config.perf.shortCut.showAndHidden.split('+'); + const showAndHiddenKeyStr = modifers.pop(); // Ctrl + const keyStr2uioKeyCode = { + Ctrl: UiohookKey.Ctrl, + Shift: UiohookKey.Shift, + Option: UiohookKey.Alt, + Command: UiohookKey.Comma, + }; + + if (uio_event.keycode === keyStr2uioKeyCode[showAndHiddenKeyStr]) { + const currentTime = Date.now(); + if (currentTime - lastModifierPress < 300) { + callback(); // 调用 mainWindowPopUp + } + lastModifierPress = currentTime; + } + }); + uIOhook.start(); +} From 5c048c6341cc4f5193b442ba81e0c936d9437f29 Mon Sep 17 00:00:00 2001 From: lanxiuyun <212650356+lanxiuyun@users.noreply.github.com> Date: Thu, 12 Jun 2025 15:08:37 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=8F=AF=E8=AF=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/common/registerHotKey.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/common/registerHotKey.ts b/src/main/common/registerHotKey.ts index 22d776f..4090368 100644 --- a/src/main/common/registerHotKey.ts +++ b/src/main/common/registerHotKey.ts @@ -58,6 +58,7 @@ const registerHotKey = (mainWindow: BrowserWindow): void => { } }; + // 显示主窗口 function mainWindowPopUp() { const currentShow = mainWindow.isVisible() && mainWindow.isFocused(); if (currentShow) return mainWindow.hide(); @@ -80,18 +81,17 @@ const registerHotKey = (mainWindow: BrowserWindow): void => { globalShortcut.unregisterAll(); // 注册偏好快捷键 - // 显示/隐藏快捷键 - if ( - ['Ctrl+Ctrl', 'Option+Option', 'Shift+Shift', 'Command+Command'].includes( - config.perf.shortCut.showAndHidden - ) - ) { - // 双击快捷键,详见 uIOhookRegister + // 处理显示/隐藏快捷键的注册 + const doublePressShortcuts = ['Ctrl+Ctrl', 'Option+Option', 'Shift+Shift', 'Command+Command']; + const isDoublePressShortcut = doublePressShortcuts.includes(config.perf.shortCut.showAndHidden); + + if (isDoublePressShortcut) { + // 双击快捷键(如 Ctrl+Ctrl)详见 uIOhookRegister 函数实现 } else { - // 普通快捷键,如 Ctrl+Space,F8 - globalShortcut.register(config.perf.shortCut.showAndHidden, () => - mainWindowPopUp() - ); + // 注册普通快捷键(如 Ctrl+Space、F8 等) + globalShortcut.register(config.perf.shortCut.showAndHidden, () => { + mainWindowPopUp(); + }); } // 截图快捷键 From 7cabbe26f50c930a4983cf09788a66be0ba69858 Mon Sep 17 00:00:00 2001 From: lanxiuyun <212650356+lanxiuyun@users.noreply.github.com> Date: Thu, 12 Jun 2025 15:09:38 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- feature/src/views/settings/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feature/src/views/settings/index.vue b/feature/src/views/settings/index.vue index 8efbed9..2a02f96 100644 --- a/feature/src/views/settings/index.vue +++ b/feature/src/views/settings/index.vue @@ -283,7 +283,7 @@ const tipText = computed(() => { const optionKeyName = isWindows ? 'Alt' : 'Option、Command'; return t('feature.settings.global.addShortcutKeyTips', { optionKeyName: optionKeyName, - }) + `此外你也可以双击修饰键如(Ctrl+Ctrl, 双击修饰键需要重启)`; + }) + `此外你也可以双击修饰键如(Ctrl+Ctrl)`; }); const currentSelect = ref(['userInfo']);