问题描述
我正在开发一个Leap Motion应用程序,已经在其中移动了光标,但是我不知道如何以编程方式触发mouseDown:(NSEvent *).
I am developing a Leap Motion Application where I already move the cursor with it, but I don't know how I can trigger a mouseDown:(NSEvent *) programmatically.
推荐答案
这对我 在可可Mac中很有效 :
This worked well for me in Cocoa Mac:
void PostMouseEvent(CGMouseButton button, CGEventType type, const CGPoint point)
{
CGEventRef theEvent = CGEventCreateMouseEvent(NULL, type, point, button);
CGEventSetType(theEvent, type);
CGEventPost(kCGHIDEventTap, theEvent);
CFRelease(theEvent);
}
使用此链接可以找到有关参数的信息: https://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html
Use this link to find out about the parameters: https://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html
例如,要在我使用的点(500,500)处触发MouseDown事件:
For example, to trigger a MouseDown event at the point (500,500) I've used:
PostMouseEvent(kCGMouseButtonLeft, NX_LMOUSEDOWN, CGPointMake(200, 200));
这篇关于如何以编程方式(无需使用鼠标)触发mouseDown:(NSEvent *)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!