Search code examples
cocoaeventsmacosmousemacos-carbon

Apple Events to Control Mouse Remotely


I'm not even sure where to begin with this question...

I want to be able to send mouse-click events to another machine, as if the user had clicked on that machine.

I can do it on the same machine via:

 CGEventSourceRef source = CGEventSourceCreate(NULL);
 CGEventType eventType = kCGEventLeftMouseDragged;
 CGPoint mouseCursorPosition;
 mouseCursorPosition.x = point.x;
 mouseCursorPosition.y = point.y;
 CGMouseButton mouseButton = kCGMouseButtonLeft;

 CGEventRef mouseEvent = CGEventCreateMouseEvent ( source,
               eventType,
               mouseCursorPosition,
               mouseButton );
 CGEventSetType(mouseEvent, kCGEventLeftMouseDragged); // Fix Apple Bug
 CGEventPost( kCGSessionEventTap, mouseEvent );
 CFRelease(mouseEvent);

But how do I send that event somewhere else? Applescript? I've read some stuff with AppleEvents being app-app communication, but I'd like to just generate a system event on another machine?

Totally unsure.

Thanks,


[Edit 11/1/10 7:30a]

Just to clarify, I'm not looking to screen share. At least I don't think so. I've got a cluster of several mac pros linked together, each has like 4 monitors. I'm trying to use only 1 device to communicate "clicks" to each of the nodes. So if the device is over node 3, but the device is plugged into node0, node0 needs to tell node 3 that it needs to respond to a click.

Thanks,


[Edit 11/4/10 9:32am]

Really? Nobody can give me a concrete code example of generating Apple Events Programmatically to create mouse events on remote machines in C/C++/Objc-C???


Solution

  • This will probably involve writing a device driver and pretending to be a mouse.