mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-22 08:47:06 +08:00
33 lines
695 B
TypeScript
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
|