Files
PicList/src/renderer/utils/key-binding.ts
2025-07-31 17:37:30 +08:00

33 lines
695 B
TypeScript

import { IRPCActionType } from '#/types/enum'
const isSpecialKey = (key: string) => {
const keyArr = ['Shift', 'Control', 'Alt', 'Meta']
return keyArr.includes(key)
}
const keyBinding = (event: KeyboardEvent) => {
const meta = window.electron.sendRpcSync(IRPCActionType.GET_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