呼出输入框
请问有没有 utools 呼出时的事件回调, 写了个循环脚本, 循环10次, 向指定聊天框发送指定文本,
想在中途终止 脚本运行
`const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
let global_stop = false
window.exports = {
"ack": {
mode: "none",
args: {
// 进入插件时调用
enter: (action) => {
utools.setSubInput(({ text }) => {
document.onkeydown = async (e) => {
window.utools.hideMainWindow()
if (!text.includes('-')) {
alert('请按正确格式输入')
return
}
const keyNum = window.event ? e.keyCode : e.which;
if(keyNum === 67){
global_stop = true
}
if (keyNum === 13) {
const params = text.split('-')
let defaultParams = {
message: params[0] || '测试发送脚本',
loop: params[1] || 20,
delay: params[2] || 1000
}
const { message, loop, delay } = defaultParams
for (let index = 0; index < loop; index++) {
if( global_stop === true ){
window.onkeydown = null
return
}
const sendMsg = `${message} ${index + 1}`
utools.copyText(sendMsg)
await sleep(delay)
utools.simulateKeyboardTap('v', utools.isMacOs() ? 'command' : 'ctrl')
await sleep(100)
utools.simulateKeyboardTap('enter')
}
// window.utools.outPlugin()
}
}
}, '请按照格式输入: 发送短语-循环次数-延迟毫秒 例子: 测试-30-1000')
},
out: (action) => {
alert('退出了')
}
}
}
}`
用了全局的 global flag 发现插件到后台时 没法监听其他按键