mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: capture keyboard event that has no key
This commit is contained in:
parent
e15bab98fc
commit
a3c8a155c2
1 changed files with 14 additions and 9 deletions
|
|
@ -38,15 +38,20 @@ function parseKeyCode(code: string) {
|
|||
|
||||
function parseEvent(e: KeyboardEvent | React.KeyboardEvent) {
|
||||
const { altKey: alt, shiftKey: shift, metaKey: meta, ctrlKey: ctrl } = e
|
||||
const code = parseKeyCode(e.key)
|
||||
const keys = { meta, ctrl, shift, alt, [code]: true }
|
||||
const combination = parse(
|
||||
Object.entries(keys)
|
||||
.filter(([key, pressed]) => pressed)
|
||||
.map(([key, pressed]) => key)
|
||||
.join('+')
|
||||
)
|
||||
return combination
|
||||
try {
|
||||
const code = parseKeyCode(e.key)
|
||||
const keys = { meta, ctrl, shift, alt, [code]: true }
|
||||
const combination = parse(
|
||||
Object.entries(keys)
|
||||
.filter(([key, pressed]) => pressed)
|
||||
.map(([key, pressed]) => key)
|
||||
.join('+'),
|
||||
)
|
||||
return combination
|
||||
} catch (err) {
|
||||
const serializedKeyData = JSON.stringify({ keyCode: e.keyCode, key: e.key })
|
||||
throw new Error(`Error parse keyboard event: ${serializedKeyData}`)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
|
|
|
|||
Loading…
Reference in a new issue