可可移动鼠标

Lan*_*opp 4 cocoa

我在Snow Leopard上写了一个Mac OS X应用程序.我有一个步骤方法,由NSTimer定期触发.在这种方法中,我想将鼠标移动到屏幕的中心,没有按下或释放按钮.这就是我所拥有的:

-(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);
}
Run Code Online (Sandbox Code Playgroud)

这没有任何作用.有人能告诉我什么是错的吗?

Joh*_*ker 7

听起来CGWarpMouseCursorPosition正是您所追求的(它移动指针而不生成事件 - 有关详细信息,请参阅Quartz Display Services Reference).