osx - User Switch Notification by Carbon in Objective C -
demonstrates how aware of user switch event . can't use code user switch purpose ,and doesn't work me. how use code notified when user switch occurs?
pascal osstatus switcheventshandler (eventhandlercallref nexthandler, eventref switchevent, void* userdata) { if (geteventkind(switchevent)== keventsystemusersessiondeactivated) { // perform deactivation tasks here. } else { // perform activation tasks here. } return noerr; } void switcheventsregister() { eventtypespec switcheventtypes[2]; eventhandlerupp switcheventhandler; switcheventtypes[0].eventclass = keventclasssystem; switcheventtypes[0].eventkind = keventsystemusersessiondeactivated; switcheventtypes[1].eventclass = keventclasssystem; switcheventtypes[1].eventkind = keventsystemusersessionactivated; switcheventhandler = neweventhandlerupp(switcheventshandler); installapplicationeventhandler(switcheventhandler, 2, switcheventtypes, null, null);
you need start event loop using runapplicationeventloop()
the main may looks this:
int main(int argc, char *argv[]) { switcheventsregister(); runapplicationeventloop(); return 0; }
Comments
Post a Comment