bugfix: os-mouse 在build后无法获取鼠标事件。改为 iohook

This commit is contained in:
muwoo
2021-07-05 20:23:06 +08:00
parent 9ab64bfa44
commit 8f2b28210f
8 changed files with 203 additions and 42 deletions

View File

@@ -1,6 +1,7 @@
import Vue from 'vue'
import axios from 'axios'
import ioHook from 'iohook';
import {ipcRenderer, remote} from 'electron';
import App from './App'
import router from './router'
import store from './store'
@@ -8,9 +9,11 @@ import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
const opConfig = remote.getGlobal('opConfig');
if (!process.env.IS_WEB) Vue.use(require('vue-electron'))
Vue.http = Vue.prototype.$http = axios
Vue.config.productionTip = false
Vue.config.productionTip = false;
Vue.use(Antd);
@@ -20,4 +23,24 @@ new Vue({
router,
store,
template: '<App/>'
}).$mount('#app')
}).$mount('#app');
ioHook.start(false);
let down_time = 0;
let isPress = false;
ioHook.on('mousedown', (e) => {
if (e.button === 1) return;
isPress = true;
down_time = Date.now();
const config = opConfig.get();
setTimeout(async () => {
if (isPress) {
ipcRenderer.send('right-down');
}
}, config.superPanel.mouseDownTime);
})
ioHook.on('mouseup', (e) => {
if(e.button === 1) return;
isPress = false;
});

View File

@@ -8,6 +8,9 @@
<a-menu-item :key="1">
超级面板
</a-menu-item>
<a-menu-item :key="2">
全局快捷键
</a-menu-item>
</a-menu>
<div class="settings-detail">
<div v-if="currentSelect[0] === 0">
@@ -65,6 +68,54 @@
</div>
<img width="100%" src="https://static.91jkys.com/upload/202107/02/fa4a5c614234409fb32ddda70cb900aa.jpg" />
</div>
<div v-if="currentSelect[0] === 2">
<a-collapse>
<a-collapse-panel key="1" header="说明及示例">
<div>按下快捷键自动搜索对应关键字当关键字结果完全匹配且结果唯一时会直接指向该功能</div>
<h3 style="margin-top: 10px;">示例</h3>
<a-divider style="margin: 5px 0;" />
<a-list item-layout="horizontal" :data-source="examples">
<a-list-item slot="renderItem" slot-scope="item, index">
<a-list-item-meta
:description="item.desc"
>
<div slot="title">{{ item.title }}</div>
</a-list-item-meta>
</a-list-item>
</a-list>
</a-collapse-panel>
</a-collapse>
<div class="feature-container">
<div class="keywords item">
<div>快捷键</div>
<a-tooltip placement="top" trigger="click">
<template slot="title">
<span>先按功能键CtrlShiftAltOptionCommand再按其他普通键或按 F1-F12 单键</span>
</template>
<div
v-for="(index, item) in config.global"
class="value"
tabIndex=-1
@keydown="(e) => changeGlobalKey(e, index)"
>
{{ item.key }}
</div>
</a-tooltip>
</div>
<div class="short-cut item">
<div>功能关键字</div>
<a-input
:value="item.value"
v-for="(index, item) in config.global"
class="value"
:disabled="!item.key"
@change="(e) => changeGlobalValue(index, e.target.value)"
/>
</div>
</div>
<div @click="addConfig" class="add-global"> + 新增全局快捷功能</div>
</div>
</div>
</div>
</div>
@@ -82,6 +133,16 @@ export default {
return {
currentSelect: [0],
config: JSON.parse(JSON.stringify(opConfig.get())),
examples: [
{
title: '快捷键 「 Alt + W」 关键字 「 微信」',
desc: '按下Alt + W 直接打开本地微信应用'
},
{
title: '快捷键 「 Alt + Q」 关键字 「 取色」',
desc: '按下Alt + Q 直接打开屏幕取色功能'
}
]
}
},
methods: {
@@ -107,6 +168,34 @@ export default {
this.config.perf.shortCut[key] = compose;
change = true;
}
},
addConfig() {
this.config.global.push({
key: '',
value: ''
});
},
changeGlobalKey(e, index) {
let compose;
if(e.altKey && e.keyCode !== 18){
compose = `Option+${keycodes[e.keyCode].toUpperCase()}`;
}
if(e.ctrlKey && e.keyCode !== 17){
compose = `Ctrl+${keycodes[e.keyCode].toUpperCase()}`;
}
if(e.shiftKey && e.keyCode !== 16){
compose = `Shift+${keycodes[e.keyCode].toUpperCase()}`;
}
if(e.metaKey && e.keyCode !== 93){
compose = `Command+${keycodes[e.keyCode].toUpperCase()}`;
}
if (compose) {
this.$set(this.config.global[index], 'key', compose);
}
},
changeGlobalValue(index, value) {
this.$set(this.config.global[index], 'value', value);
}
},
watch: {
@@ -170,5 +259,35 @@ export default {
}
}
}
.feature-container {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 10px;
font-size: 14px;
.item {
flex: 1;
}
.short-cut {
margin-left: 20px;
}
.value {
text-align: center;
border: 1px solid #ddd;
color: #6C9FE2;
font-size: 14px;
height: 24px;
font-weight: lighter;
margin-top: 10px;
}
}
.add-global {
color: #6C9FE2;
margin-top: 20px;
width: 100%;
text-align: center;
cursor: pointer;
}
}
</style>