4

I'm writing a Mac OS X application on Snow Leopard. I have a step method which is fired at a regular interval by a NSTimer. In this method I would like to move the mouse to the center of the screen, with no buttons being pressed or released. Here's 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);
}

This doesn't do anything. Can somebody tell me what's wrong?

LandonSchropp
  • 9,623
  • 17
  • 82
  • 146

1 Answers1

7

It sounds like CGWarpMouseCursorPosition is precisely what you're after (it moves the pointer without generating events - see the Quartz Display Services Reference for more info).

John Parker
  • 53,316
  • 11
  • 128
  • 128