I used the following code to program click programming on Mac
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 Click(const CGPoint point)
{
PostMouseEvent(kCGMouseButtonLeft, kCGEventMouseMoved, point);
NSLog(@"Click!");
PostMouseEvent(kCGMouseButtonLeft, kCGEventLeftMouseDown, point);
PostMouseEvent(kCGMouseButtonLeft, kCGEventLeftMouseUp, point);
}
Now I'm trying to click down to be able to drag objects like a scroll bar or application window. I am using the following:
PostMouseEvent(kCGMouseButtonLeft, kCGEventMouseMoved, point);
NSLog(@"Click Down!");
PostMouseEvent(kCGMouseButtonLeft, kCGEventLeftMouseDown, point);
When I run the code above, something interesting will happen, when the left mouse button gives nothing, nothing happens, I move the mouse, and the window does not move, however, when I added the mouse up , then the window jumped to the place where I supposedly dragged him. it's kind of OK, however, how can I make a mouse click and drag an object?
Note. I have a whole method to see when the mouse stopped moving, so I can click.
please send the code. Thanks