如何收听全屏点击事件

时间:2016-11-02 18:25:41

标签: javascript electron

电子新手。工作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'));     
})

1 个答案:

答案 0 :(得分:1)

这将有效,

document.body.addEventListener('click', fn, true);