Skip to content

Instantly share code, notes, and snippets.

@Noitidart
Created June 17, 2021 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Noitidart/6a5e4b90cded9ed7f65a13edaeff26ca to your computer and use it in GitHub Desktop.
Save Noitidart/6a5e4b90cded9ed7f65a13edaeff26ca to your computer and use it in GitHub Desktop.
Cu.import('resource://gre/modules/ctypes.jsm');
const cg = ctypes.open('/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics');
const CFTimeInterval = ctypes.double;
const CGEventSourceStateID = ctypes.uint32_t;
const CGEventType = ctypes.uint32_t;
const kCGEventSourceStateCombinedSessionState = 0;
const kCGAnyInputEventType = 0xFFFFFFFF;
const CGEventSourceSecondsSinceLastEventType = cg.declare("CGEventSourceSecondsSinceLastEventType", ctypes.default_abi, CFTimeInterval, CGEventSourceStateID, CGEventType);
function calculateIdleTime() {
return CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateCombinedSessionState, kCGAnyInputEventType);
}
console.log('calculateIdleTime:', calculateIdleTime());
setTimeout(() => {
console.log('calculateIdleTime:', calculateIdleTime());
cg.close();
}, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment