Cocoa Move Mouse

I am writing a Mac OS X application on Snow Leopard. I have a steps method that runs at regular intervals using NSTimer. In this method, I would like to move the mouse to the center of the screen, without pressing or releasing the buttons. Here is what I have:

-(void) step: (NSTimer *) timer { NSRect bounds = [self bounds]; CGPoint point = CGPointMake(bounds.origin.x + bounds.size.width / 2.0f, bounds.origin.y + bounds.size.height / 2.0f); CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDragged, point, 0); } 

It does nothing. Can someone tell me what's wrong?

+4
source share
1 answer

It seems that CGWarpMouseCursorPosition is exactly what you need (it moves the pointer without generating events - see the Quartz Display Services Reference for more information).

+7
source

All Articles