可可移动鼠标 [英] Cocoa Move Mouse
本文介绍了可可移动鼠标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Snow Leopard上写了一个Mac OS X应用程序。我有一个步骤方法,由NSTimer定期间隔。在这种方法中,我想将鼠标移动到屏幕的中心,没有按下或释放按钮。这是我有的:
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);
}
推荐答案
这听起来像CGWarpMouseCursorPosition正是你的后面(它移动指针而不生成事件 - 有关详情,请参见 Quartz Display Services参考 )。
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).
这篇关于可可移动鼠标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文