mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-07-09 14:31:47 +08:00
🔨 Refactor(ts): change js -> ts
This commit is contained in:
38
src/renderer/utils/key-binding.ts
Normal file
38
src/renderer/utils/key-binding.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import keycode from 'keycode'
|
||||
|
||||
const isSpecialKey = (keyCode: number) => {
|
||||
const keyArr = [
|
||||
16, // Shift
|
||||
17, // Ctrl
|
||||
18, // Alt
|
||||
91, // Left Meta
|
||||
93 // Right Meta
|
||||
]
|
||||
|
||||
return keyArr.includes(keyCode)
|
||||
}
|
||||
|
||||
const keyDetect = (event: KeyboardEvent) => {
|
||||
const meta = process.platform === 'darwin' ? 'Cmd' : 'Super'
|
||||
let specialKey = {
|
||||
Ctrl: event.ctrlKey,
|
||||
Shift: event.shiftKey,
|
||||
Alt: event.altKey,
|
||||
[meta]: event.metaKey
|
||||
}
|
||||
|
||||
let pressKey = []
|
||||
|
||||
for (let i in specialKey) {
|
||||
if (specialKey[i]) {
|
||||
pressKey.push(i)
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSpecialKey(event.keyCode)) {
|
||||
pressKey.push(keycode(event.keyCode).toUpperCase())
|
||||
}
|
||||
return pressKey
|
||||
}
|
||||
|
||||
export default keyDetect
|
||||
Reference in New Issue
Block a user