Created
June 17, 2021 21:01
-
-
Save Noitidart/6a5e4b90cded9ed7f65a13edaeff26ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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