Hello every one !
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 !
Answers(1)
-
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:[self postMouseEventWithButton:0 withType:kCGEventMouseMoved andPoint:point];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:
CGEventSetIntegerValueField(event, kCGMouseEventClickState, 1);... because some applications need it.
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.
More about Simulate mouse on Mac
-
Mac OS X Terminal: mouse support?
Is there a native option (ie. without installing extra soft/package/plugins) to enable mouse support in the Terminal app? Actually, I'm using a lot vim with the option set mouse=a (activating mouse ... -
How to open folder without using mouse in Mac?
I'm recently switched to Mac from windows, I was quite pain but now adjusted to the Mac commands and shortcuts except one, that is whenever select folder and hit return/enter ... -
how to make right click of mouse on Mac
Hello everyone, I am using a MacBook Pro running Mac OS X 10.5. I am new to this development environment, and previously worked on Windows. I am wondering how to make right ... -
Clicking the mouse down to drag objects on Mac
I've been using the following code to issue clicks programmatically on a Mac void PostMouseEvent(CGMouseButton button, CGEventType type, const CGPoint point) { CGEventRef theEvent = CGEventCreateMouseEvent(NULL, type, point, button); CGEventSetType(theEvent, type); ... -
Vim and mouse with ssh from Mac to Linux
Hey. I certainly know it's possible to make the mouse work in Vim on a remote session to a Linux machine from my Mac, but I haven't figured out just how. Daily ... -
Getting "global" mouse position in Mac OS X
How can I get in Mac OS X "global" mouse position - I mean how can I in cocoa/cf/whatever find out cursor position even if it's outside the window, and ... -
Mouse bugginess - SWFObject, Firefox 3 for Mac, and Flash
I'm pulling my hair out over a problem I'm encountering on Firefox 3.5 & 3.6 on OS X. I'm using SWFobject to embed an AmMap of the US, which has ... -
Generating mouse events in Mac OS X
Hi, I have an USB device that will send out some proprietary data and I have some algorithm that converts it to mouse coordinates, the question I have is how do ... -
Using Ruby on Mac OS X, how to programmatically click on the screen -- and mouse move, mouse down, and mouse up?
What are the best way(s) to do it? Can ffi, RubyCocoa, or MacRuby do it? It seems like CGEventCreateMouseEvent or CGPostMouseEvent (deprecated) can be used. Please give a working example. thanks. Update: ... -
directx mouse click simulation
How can I simulate the mouse click in a directx application? mouse_event and PostMessage with WM_LBUTTONDOWN don't work... so it must be something to do with the DirectInput I haven't found out nothing ...