• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: User In-Activity hook? And a request
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: User In-Activity hook? And a request


  • Subject: Re: User In-Activity hook? And a request
  • From: Scott Ribe <email@hidden>
  • Date: Tue, 10 Mar 2009 10:19:22 -0600
  • Thread-topic: User In-Activity hook? And a request

For anybody who cares, the following predates CGSecondsSinceLastInputEvent,
and uses only public APIs. It's probably just personal preference as to
which is less vile ;-)

- (float) getSystemIdleSeconds
{
    static mach_port_t masterPort = 0;
    static io_iterator_t iter;
    static io_registry_entry_t curio;

    if( masterPort == 0 )
    {
        if( IOMasterPort( MACH_PORT_NULL, &masterPort ) == KERN_SUCCESS &&
                IOServiceGetMatchingServices( masterPort, IOServiceMatching(
"IOHIDSystem" ), &iter ) == KERN_SUCCESS )
        {
            curio = IOIteratorNext( iter );
            IOObjectRelease( iter );
        }
    }

    CFTypeRef obj = 0;
    if( curio )
        obj = IORegistryEntryCreateCFProperty( curio, CFSTR( "HIDIdleTime"
), kCFAllocatorDefault, 0 );

    float val = 0;
    if( obj )
    {
        uint64_t nano = 0;
        CFTypeID type = CFGetTypeID( obj );

        if( type == CFDataGetTypeID() )
            CFDataGetBytes( (CFDataRef) obj, CFRangeMake( 0, sizeof( nano
)), (UInt8*) &nano );
        else if( type == CFNumberGetTypeID() )
            CFNumberGetValue( (CFNumberRef) obj, kCFNumberSInt64Type, &nano
);

        CFRelease( obj );

        val = nano / 1000000000.0;
    }

    return val;
}


--
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 722-0567 voice


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: User In-Activity hook? And a request (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: launching IPhone App Via terminal in IPhone Simulator
  • Next by Date: KVO & Bindings: Proxy object & change notifications
  • Previous by thread: Re: User In-Activity hook? And a request
  • Next by thread: Automatically select current system's timezone from popup button
  • Index(es):
    • Date
    • Thread