Simulating mouse clicks on Mac OS X does not work for some applications.

Posted by Thomi on Stack Overflow See other posts from Stack Overflow or by Thomi
Published on 2010-03-03T08:52:06Z Indexed on 2010/05/01 12:07 UTC
Read the original article Hit count: 308

Filed under:
|
|
|

I'm writing an application for Mac OS X 10.6 and later in C++. One part of the application needs to simulate mouse movement and mouse clicks. I do this currently by posting CGEvent objects using CGEventPost(kCGHIDEventTap, event);.

This works, for the most part - I can simulate mouse movement and clicks just fine, but it seems to fail in some areas. For example:

  • In Mozilla Firefox and Safari, I can click on all the menus, but cannot click on a link within a website. When I try, the link is highlighted, but the browser never follows the link. However, I can right-click on a link, select "open link in new tab", and everything works as expected. Solved - creating the mouse event using CGEventCreateMouseEvent(...) makes the event work within web browser.
  • I can click on the "Dashboard" icon to brink up the dashboard, but I cannot click on the "i" button on any of the dashboard widgets. Similarly, clicking on any of the search results from the spotlight search widget doesn't work either.

This inconsistency is along application boundaries. What might be the cause?

© Stack Overflow or respective owner

Related posts about c++

Related posts about mac