Search code examples
macosmacos-carbon

What's the right replacement for PostEvent


I'm getting a warning that PostEvent is deprecated and I assume that one is supposed to use PostEventToQueue but it takes two extra parameters and I can't find any documentation on what combination of parameters (one is a queue specification, the other is an event priority) will be equivalent to PostEvent.


Solution

  • PostEventToQueue is for a Carbon Event, not a low-level OS event like PostEvent. If you want to post a keyboard or mouse event, you should use CGEventPost.

    Edit to add: To post a mouse down at the current location, I think (untested) that you can do this:

    CGEventRef theEvent = CGEventCreate( NULL );
    CGEventSetType( theEvent, kCGEventLeftMouseDown );
    CGEventPost( theEvent );
    CFRelease( theEvent );