I have a virtual trackpad on my iPhone and to move my mouse I’m using :
CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, CGPointMake(((float)aD.msg)+location.x, ((float)aD.msg2)+location.y));
It’s working well but this not a real mouse because when I put my mouse on my hidden dock, this one doesn’t display it self. I don’t understand why.
More over I tried to simulate mouse click with :
case MOUSECLICK:
[self postMouseEventWithButton:0 withType:kCGEventLeftMouseDown andPoint:CGEventGetLocation(CGEventCreate(NULL))];
[self postMouseEventWithButton:0 withType:kCGEventLeftMouseUp andPoint:CGEventGetLocation(CGEventCreate(NULL))];
// *********************
-(void)postMouseEventWithButton:(CGMouseButton)b withType:(CGEventType)t andPoint:(CGPoint)p
{
CGEventRef theEvent = CGEventCreateMouseEvent(NULL, t, p, b);
CGEventSetType(theEvent, t);
CGEventPost(kCGHIDEventTap, theEvent);
CFRelease(theEvent);
}
Is it the good method? Thanks for your help !
CGDisplayMoveCursorToPoint()only moves the image of the cursor, it does not generate any events. You should create and post mouse events of typekCGEventMouseMovedto simulate moving the mouse. Your own method would do it:For clicks, you are already doing it the right way, I think. One thing you should also do is set the click count properly on both the mouse down and mouse up events, like so:
… because some applications need it.
(See also Simulating mouse clicks on Mac OS X does not work for some applications)
If your code doesn’t work, I’m not sure why; it looks OK to me. Try posting to
kCGSessionEventTapinstead ofkCGHIDEventTapand see if it helps. Also, you don’t need theCGEventSetType()call since the type is already set in the creation call.