Re: User In-Activity hook? And a request
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