mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-23 01:00:35 +08:00
31 lines
617 B
TypeScript
31 lines
617 B
TypeScript
const isSpecialKey = (key: string) => {
|
|
const keyArr = ['Shift', 'Control', 'Alt', 'Meta']
|
|
|
|
return keyArr.includes(key)
|
|
}
|
|
|
|
const keyBinding = (event: KeyboardEvent) => {
|
|
const meta = window.electron.platform === 'darwin' ? 'Cmd' : 'Super'
|
|
const specialKey = {
|
|
Ctrl: event.ctrlKey,
|
|
Shift: event.shiftKey,
|
|
Alt: event.altKey,
|
|
[meta]: event.metaKey,
|
|
}
|
|
|
|
const pressKey = []
|
|
|
|
for (const i in specialKey) {
|
|
if (specialKey[i]) {
|
|
pressKey.push(i)
|
|
}
|
|
}
|
|
|
|
if (!isSpecialKey(event.key)) {
|
|
pressKey.push(event.key.toUpperCase())
|
|
}
|
|
return pressKey
|
|
}
|
|
|
|
export default keyBinding
|