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