Reputation: 129
I'm trying to get a detect event whenever I switch to another active window. I know there are modules on npm that tells you the active window, but is there an Electron native way to detect a change in the active window(that is not my electron app itself, but some other completely unrelated app.
Thanks!
Upvotes: 3
Views: 3436
Reputation: 4491
BrowserWindow has a 'blur' event which is triggered when the window looses focus, and the app has a 'browser-window-blur' event which is called when any of the created windows looses focus.
const {app} = require('electron')
app.on('browser-window-blur', () => {
// Your code
})
If you talk about external Windows you need to go via a native module to solve that, electron and nodejs have no build in function for that. Native modules are extensions to normal JavaScript and they are written in diffrent languages for example C/C++ and exported/compiled to be used with nodeJS.
For talking to the Windows OS API you could use node-winapi
if you want to do it yourself. Otherwise i would encourage you to use a library which does this already. Just be sure that it works with the nodeJS version that Electron uses currently nodeJS v8.9.3
Upvotes: 3