Re: Preventing screen-saver from triggering ?
Re: Preventing screen-saver from triggering ?
- Subject: Re: Preventing screen-saver from triggering ?
- From: Shaun Wexler <email@hidden>
- Date: Tue, 18 Nov 2003 12:45:56 -0800
On Nov 18, 2003, at 7:06 AM, Rolf wrote:
Hi everyone!
Anyone know how to programatically prevent the screen-saver from
triggering ? I have tried "fooling" the system by making minute mouse
pointer movements every 15 seconds (using CGWarpMouseCursorPosition),
but that didn't work ..
How about something like this?
#import <Cocoa/Cocoa.h>
#import <IOKit/hidsystem/IOHIDLib.h>
@implementation NSApplication (SKWInsomnia)
- (void)allowSleep:(BOOL)sleepAllowed
{
static NSTimer *timer = nil;
if (sleepAllowed && timer) {
[timer invalidate]; // released by the NSRunLoop
timer = nil;
}
if (!sleepAllowed && !timer) {
timer = [NSTimer scheduledTimerWithTimeInterval:20.0 target:self
selector:@selector(tickleHIDEventTimer:) userInfo:nil repeats:YES];
}
}
- (void)tickleHIDEventTimer:(NSTimer *)timer
{
IOGPoint locPoint;
kern_return_t kr;
mach_port_t masterPort, service, iter;
NXEvent nullEvent = {NX_NULLEVENT, {0, 0}, 0, -1, 0};
static io_connect_t serviceConnection = MACH_PORT_NULL;
if (serviceConnection == MACH_PORT_NULL)
{
kr = IOMasterPort(MACH_PORT_NULL, &masterPort);
if (kr == KERN_SUCCESS && masterPort)
{
kr = IOServiceGetMatchingServices(masterPort,
IOServiceMatching(kIOHIDSystemClass), &iter);
if (kr == KERN_SUCCESS)
{
service = IOIteratorNext(iter);
kr = IOServiceOpen(service, mach_task_self(),
kIOHIDParamConnectType, &serviceConnection);
IOObjectRelease(service);
IOObjectRelease(iter);
}
}
if (masterPort) {
IOObjectRelease(masterPort);
masterPort = MACH_PORT_NULL;
}
if (kr != KERN_SUCCESS) {
serviceConnection = MACH_PORT_NULL;
return;
}
}
if (serviceConnection != MACH_PORT_NULL) {
kr = IOHIDPostEvent(serviceConnection, NX_NULLEVENT, locPoint,
&nullEvent.data, FALSE, 0, FALSE);
}
}
@end
Typed in Mail.app; usual disclaimer applies...
--
Shaun Wexler
MacFOH
http://www.macfoh.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.