views:

330

answers:

1

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!

+3  A: 

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);
}
phoebus
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); }
Uri
oops, sorry for the poor formatting
Uri
At first glance that looks about right.
phoebus
It seems to be working great! Thanks
Uri