CGPostMouseEvent replacement on Snow Leopard

前端 未结 1 1900
星月不相逢
星月不相逢 2021-01-12 09:03

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,

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-12 09:45

    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);
    }
    

    0 讨论(0)
提交回复
热议问题