I'm using the following code to simulate a click of the mouse:
void PostMouseEvent(CGMouseButton button, CGEventType type, const CGPoint point)
{
CGEventRef theEvent = CGEventCreateMouseEvent(NULL, type, point, button);
CGEventSetType(theEvent, type);
CGEventPost(kCGHIDEventTap, theEvent);
CFRelease(theEvent);
}
void LeftClick(const CGPoint point)
{
PostMouseEvent(kCGMouseButtonLeft, kCGEventMouseMoved, point);
NSLog(@"Click!");
PostMouseEvent(kCGMouseButtonLeft, kCGEventLeftMouseDown, point);
PostMouseEvent(kCGMouseButtonLeft, kCGEventLeftMouseUp, point);
}
I can use basically the same code to do a control-click (right click) by changing:
kCGEventLeftMouseDown
kCGEventLeftMouseUp
kCGMouseButtonLeft
to their respective "Right" events. The function looks something like:
void RightClick(const CGPoint point)
{
PostMouseEvent(kCGMouseButtonRight, kCGEventMouseMoved, point);
NSLog(@"Click Right");
PostMouseEvent(kCGMouseButtonRight, kCGEventRightMouseDown, point);
PostMouseEvent(kCGMouseButtonRight, kCGEventRightMouseUp, point);
}
But, how about a double click? I tried sending 2 leftclicks and calling PostMouseEvent() twice in a row but no luck. How do you perform a double click?
thanks!
See Question&Answers more detail:os