Synthetic click doesn't switch application's menu bar (Mac OS X)

Posted by Rok on Stack Overflow See other posts from Stack Overflow or by Rok
Published on 2010-04-08T17:47:16Z Indexed on 2010/05/10 11:34 UTC
Read the original article Hit count: 190

Filed under:
|
|
|
|

Hi. I'm developing some sort of air mouse application for iPhone platform. This applications connects to one computer service which generates mouse events on Mac OS X. I'm generating this events with CGEventCreateMouseEvent() and CGEventPost(). But I've encountered one problem. Let's say you are using Safari and then you click on free desktop space. If you do this with regular mouse it will hide Safari's top menu bar and show Finder menu bar. But on these synthetic events it doesn't act like that. Do I have to post some other event or set some additional properties?

Here is my code for mouse up, mouse down:

- (void)mouseUp:(int)button {
    int type = (button == LEFT_BUTTON) ? kCGEventLeftMouseUp : kCGEventRightMouseUp;
    int mouseButton = (button == LEFT_BUTTON) ? kCGMouseButtonLeft : kCGMouseButtonRight;
    leftMouseDown = (button == LEFT_BUTTON) ? NO : leftMouseDown;
    rightMouseDown = (button == RIGHT_BUTTON) ? NO : rightMouseDown;
    CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
    CGEventRef event = CGEventCreateMouseEvent (source, type, CGSCurrentInputPointerPosition(), mouseButton);
    CGEventSetType(event, type);
    CGEventPost(kCGHIDEventTap, event);
    CFRelease(event);
}
- (void)mouseDown:(int)button {
    int type = (button == LEFT_BUTTON) ? kCGEventLeftMouseDown : kCGEventRightMouseDown;
    int mouseButton = (button == LEFT_BUTTON) ? kCGMouseButtonLeft : kCGMouseButtonRight;
    leftMouseDown = (button == LEFT_BUTTON) ? YES : leftMouseDown;
    rightMouseDown = (button == RIGHT_BUTTON) ? YES : rightMouseDown;
    CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
    CGEventRef event = CGEventCreateMouseEvent (source, type, CGSCurrentInputPointerPosition(), mouseButton);
    CGEventSetType(event, type);
    CGEventPost(kCGHIDEventTap, event);
    CFRelease(event);
}

© Stack Overflow or respective owner

Related posts about mouse

Related posts about events