Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 258
Uri Avatar asked Sep 27 '09 13:09

Uri


1 Answers

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);
}
like image 186
phoebus Avatar answered Oct 13 '22 21:10

phoebus