anaisbetts/node-system-idle-time

Idle time on macOS Sierra doesn't account for keyboard input

nickav opened this issue · 1 comments

The idle time on macOS Sierra doesn't get reset when on macOS Sierra. I switched the Mac native plugin to use the following script and now idle time gets reset when you type as it should.

#import <CoreFoundation/CoreFoundation.h>
#import <AppKit/AppKit.h>

/**
 Returns the number of seconds the machine has been idle or -1 if an error occurs.
 The code is compatible with Tiger/10.4 and later (but not iOS).
 */
int32_t SystemIdleTime(void) {
  double idleSeconds = CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateHIDSystemState, kCGAnyInputEventType);
  return (int32_t) (idleSeconds * 1000);
}

can you guide me how to use this thing? There is no documentation on this module