简体   繁体   中英

CGPostMouseEvent replacement on Snow Leopard

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

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

That's all.

Any ideas?

Thanks!

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


Edit from OP:

Something like this?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM