From 9b776608186b2fcaa7b222ff26ea50c4b00c5dde Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Wed, 22 Nov 2023 12:20:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A2=84=E8=A7=88=E8=A6=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=88=90=E7=9A=84=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/ui/hotkey.vue | 54 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/src/ui/hotkey.vue b/src/ui/hotkey.vue index f46d87e..ad6c768 100644 --- a/src/ui/hotkey.vue +++ b/src/ui/hotkey.vue @@ -136,7 +136,10 @@ function unwarpAssist(assist: number) { } function getKeyShow(key: KeyCode, assist: number) { - return unwarpAssist(assist) + KeyCodeUtils.toString(key); + return ( + unwarpAssist(assist) + + (key === KeyCode.Unknown ? '' : KeyCodeUtils.toString(key)) + ); } function select(id: string, index: number) { @@ -146,43 +149,72 @@ function select(id: string, index: number) { function keyup(e: KeyboardEvent) { if (selectedKey.id === 'none') return; + e.preventDefault(); const code = keycode(e.keyCode); - if ( - code === KeyCode.Ctrl || - code === KeyCode.Shift || - code === KeyCode.Alt - ) { - return; - } + const assist = generateBinary([e.ctrlKey, e.shiftKey, e.altKey]); const id = selectedKey.index === -1 ? selectedKey.id : `${selectedKey.id}_${selectedKey.index}`; - hotkey.set(id, code, assist); const key = keyData[selectedGroup.value][selectedKey.id].keys.find( v => v.index === selectedKey.index ); + if (key) { - key.key = code; - key.assist = assist; + if ( + code === KeyCode.Ctrl || + code === KeyCode.Shift || + code === KeyCode.Alt + ) { + const data = hotkey.data[id]; + key.assist = generateBinary([data.ctrl, data.shift, data.alt]); + key.key = data.key; + } else { + key.key = code; + key.assist = assist; + hotkey.set(id, code, assist); + } } selectedKey.id = 'none'; selectedKey.index = -1; } +function keydown(e: KeyboardEvent) { + if (selectedKey.id === 'none') return; + e.preventDefault(); + const code = keycode(e.keyCode); + const assist = generateBinary([e.ctrlKey, e.shiftKey, e.altKey]); + const key = keyData[selectedGroup.value][selectedKey.id].keys.find( + v => v.index === selectedKey.index + ); + if (!key) return; + key.assist = assist; + key.key = KeyCode.Unknown; + + if ( + code !== KeyCode.Ctrl && + code !== KeyCode.Shift && + code !== KeyCode.Alt + ) { + key.key = code; + } +} + // ban other keys gameKey.disable(); onMounted(() => { document.addEventListener('keyup', keyup); + document.addEventListener('keydown', keydown); }); onUnmounted(() => { gameKey.enable(); document.removeEventListener('keyup', keyup); + document.removeEventListener('keydown', keydown); });