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

前端 未结 4 1201
走了就别回头了
走了就别回头了 2020-12-03 02:13

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

相关标签:
4条回答
  • 2020-12-03 02:43

    I have written how to do it in the blog post Python Mouse Click and Move Mouse on Apple Mac OS X Snow Leopard 10.6.x.

    0 讨论(0)
  • 2020-12-03 02:44

    Use OSXVnc. I see they use CGPostMouseEvent() instead of CGPostEvent().

    0 讨论(0)
  • 2020-12-03 02:48

    What you need to do to convince these applications that you have in fact generated a click is to explicitly set the value of the "click state" field on the mouse up event to 1 (it defaults to 0). The following code will do it:

    CGEventSetIntegerValueField(event, kCGMouseEventClickState, 1);
    

    It also has to be set to 1 for the mouse down, but by using CGEventCreateMouseEvent() rather than CGEventCreate() that gets done for you.

    I have tested this and it works in the 'i' buttons in the dashboard and the Spotlight search results.

    (As an aside, if you were simulating a double click you would need to set the click state to 2 for both the mouse down and mouse up events of the second click.)

    0 讨论(0)
  • 2020-12-03 02:55

    Most menus are activated with the mouseDown event. Hyperlinks are followed after the mouseUp event. The "i" button only works when the mouse has been clicked but not a long time. All this seem to show that you have a timing problem, try several pressed timing.

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