雪豹上的CGPostMouseEvent替换 [英] CGPostMouseEvent replacement on Snow Leopard

查看:214
本文介绍了雪豹上的CGPostMouseEvent替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自Mac OS 10.4起,我一直在使用CGPostMouseEvent()执行鼠标单击.

I've been using CGPostMouseEvent() for performing mouse clicks since mac os 10.4.

在处理我的代码并尝试使其与Snow Leopard 100%兼容时,XCode吐出警告说CGPostMouseEvent()已弃用. 尽管这并不吓我,但我想知道是什么代替了CGPostMouseEvent(). 这是我的用法:

While working on my code and trying to make it 100% compatible with Snow Leopard, XCode spit a warning saying that CGPostMouseEvent() is deprecated. While this doesn't scare me, I'd like to know what replaces CGPostMouseEvent(). This is how I use it:

CGPostMouseEvent(point,FALSE,1,TRUE);  // mouse down
CGPostMouseEvent(point,FALSE,1,FALSE); // mouse up

仅此而已.

有什么想法吗?

谢谢!

推荐答案

CGEventCreateMouseEvent可以以不推荐使用的方式与CGEventPost一起使用.参考是

CGEventCreateMouseEvent can be used with CGEventPost in a non-deprecated fashion. The reference is here.

从OP

像这样吗?

void PostMouseEvent(CGMouseButton button, CGEventType type, const CGPoint point)
{
    CGEventRef theEvent = CGEventCreateMouseEvent(NULL, type, point, button);
    CGEventSetType(theEvent, type);
    CGEventPost(kCGHIDEventTap, theEvent);
    CFRelease(theEvent);
}

这篇关于雪豹上的CGPostMouseEvent替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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