How to check when a computer is in standby mode in NodeJS?

I want to run a process in the background in NodeJS, which waits until the computer has been used for 10 minutes. I mean, the user does not touch the keyboard or mouse.

In other words: I want to listen to keyboard and mouse events in any window and notify my application when this happens.

For this mission, I can use simple node, or nw.js or electron.

I think I should use C ++, a native module and a DLL. But I hope there is a better and simpler solution.

You have?

+5
source share
3 answers
+1
source

I was able to get user downtime on OSX using ioreg from this previous answer .

 var child_process = require('child_process'); function idleTime(callback) { var command = `ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF/1000000000; exit}'`; child_process.exec(command, function(err, stdout, stderr) { return err ? callback(err) : callback(null, stdout.trim()); }); } setInterval(function() { idleTime(function(err, duration) { console.log(`idle for ${Math.round(duration)} seconds`) }) }, 1000); 
0
source

You can try https://github.com/bithavoc/node-desktop-idle , which works on Linux, OSX and Windows. I built it for Electron, but it works in Node.js in general.

0
source

All Articles