Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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???

like image 954
Stephen Furlani Avatar asked Oct 29 '10 11:10

Stephen Furlani


2 Answers

As I understand it, you can use Distributed Objects to pass the Apple Events along.

They can work across the network via Bonjour. You could serialise or encode an Apple Event pass it across the network then have a helper app running on the machine at the other end to listen for, decode the Event and run it. You may just want to encode the coordinates of the mouse click for simplicity.

I also believe Marcus Zarra's book on Core Data has the sample code for a Core Data app running over a network which uses DO. You might be able to see what he's done and do something similar to get you started. See also this excellent Q&A on DO by Mike Ash.

like image 125
John Gallagher Avatar answered Oct 22 '22 00:10

John Gallagher


the "System Events" "application" (just a process in reality) allows to send events using applescript:

tell application "System Events"
tell process "Finder"
click at {10, 10}
end tell
end tell
like image 22
Pizzaiola Gorgonzola Avatar answered Oct 22 '22 00:10

Pizzaiola Gorgonzola