电子新手。工作menubar app。即使菜单栏项目已关闭,我也会跟踪鼠标位置,但我也想在屏幕上的任何位置收听click
事件。我怎么能这样做?
const electron = require('electron')
var menubar = require('menubar');
var mb = menubar()
function myCallback() {
var mouse = electron.screen.getCursorScreenPoint()
console.log("Mouse is at x:" + mouse.x + " y:" + mouse.y);
}
mb.on('ready', function ready () {
console.log('app is ready')
var intervalID = setInterval(myCallback, 100);
//this doesn't work right now
electron.screen.addEventListener("click", console.log('clicked'));
})
答案 0 :(得分:1)
这将有效,
document.body.addEventListener('click', fn, true);