Best way to know if application is inactive in cocoa mac OSX?

前端 未结 5 1895
旧时难觅i
旧时难觅i 2021-02-09 06:03

So, i am building a program that will stand on a exhibition for public usage, and i got a task to make a inactive state for it. Just display some random videos from a folder on

5条回答
  •  梦谈多话
    2021-02-09 06:32

    You can use CGEventSourceSecondsSinceLastEventType

    Returns the elapsed time since the last event for a Quartz event source.

    /*
     To get the elapsed time since the previous input event—keyboard, mouse, or tablet—specify kCGAnyInputEventType.
     */
    - (CFTimeInterval)systemIdleTime
    {       
        CFTimeInterval timeSinceLastEvent = CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateHIDSystemState, kCGAnyInputEventType);
        return timeSinceLastEvent;
    }
    

提交回复
热议问题