如何以编程方式(无需使用鼠标)触发mouseDown:(NSEvent *)? [英] How to trigger a mouseDown:(NSEvent *) programmatically (without using the mouse)?

查看:223
本文介绍了如何以编程方式(无需使用鼠标)触发mouseDown:(NSEvent *)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个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);
}

使用此链接可以找到有关参数的信息:

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 *)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆