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

前端 未结 5 1920
旧时难觅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:42

    I'm expanding on Parag Bafna's answer. In Qt you can do

    #include 
    
    double MyClass::getIdleTime() {
        CFTimeInterval timeSinceLastEvent = CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateHIDSystemState, kCGAnyInputEventType);
        return timeSinceLastEvent;
    }
    

    You also have to add the framework to your .pro file:

    QMAKE_LFLAGS += -F/System/Library/Frameworks/ApplicationServices.framework
    LIBS += -framework ApplicationServices
    

    The documentation of the function is here

提交回复
热议问题