修改按键绑定机制
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
import mousetrap from 'mousetrap'
|
||||
|
||||
let eventHub
|
||||
|
||||
const bindKeys = [
|
||||
'shift',
|
||||
'mod',
|
||||
'mod+a',
|
||||
]
|
||||
|
||||
const bindKey = () => {
|
||||
mousetrap.reset()
|
||||
for (const key of bindKeys) {
|
||||
mousetrap.bind(key, (event, combo) => {
|
||||
eventHub.$emit(`key_${key}_down`, { event, combo })
|
||||
return false
|
||||
}, 'keydown')
|
||||
mousetrap.bind(key, (event, combo) => {
|
||||
eventHub.$emit(`key_${key}_up`, { event, combo })
|
||||
return false
|
||||
}, 'keyup')
|
||||
}
|
||||
}
|
||||
|
||||
const unbindKey = () => {
|
||||
for (const key of bindKeys) {
|
||||
mousetrap.unbind(key, 'keydown')
|
||||
mousetrap.unbind(key, 'keyup')
|
||||
}
|
||||
}
|
||||
|
||||
const handleFocus = () => {
|
||||
for (const key of bindKeys) {
|
||||
eventHub.$emit(`key_${key}_up`, { combo: key })
|
||||
}
|
||||
}
|
||||
|
||||
export default () => {
|
||||
eventHub = window.eventHub
|
||||
|
||||
eventHub.$on('bindKey', bindKey)
|
||||
eventHub.$on('unbindKey', unbindKey)
|
||||
eventHub.$on('focus', handleFocus)
|
||||
}
|
||||
@@ -1,11 +1,18 @@
|
||||
import Vue from 'vue'
|
||||
import bindkey from './bindkey'
|
||||
import keyBind from '../utils/keyBind'
|
||||
import { rendererOn } from '../../common/ipc'
|
||||
|
||||
window.eventHub = new Vue()
|
||||
const eventHub = window.eventHub = new Vue()
|
||||
|
||||
bindkey()
|
||||
eventHub.$on('bindKey', () => {
|
||||
keyBind.bindKey((key, type, event, keys) => {
|
||||
// console.log(`key_${key}_${type}`)
|
||||
eventHub.$emit(`key_${key}_${type}`, { event, keys, key })
|
||||
})
|
||||
})
|
||||
eventHub.$on('unbindKey', keyBind.unbindKey)
|
||||
|
||||
rendererOn('focus', () => {
|
||||
window.eventHub.$emit('focus')
|
||||
keyBind.clearDownKeys()
|
||||
eventHub.$emit('focus')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user