Apple Events to Control Mouse Remotely

你。 提交于 2019-12-21 12:44:14

问题


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


回答1:


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




回答2:


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.




回答3:


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



回答4:


I'm going answer out of the box, and suggest you try Synergy, as it sounds like what you are looking for. If not, since it's open source code taking a look at it might give you an idea on how to proceed.



来源:https://stackoverflow.com/questions/4051587/apple-events-to-control-mouse-remotely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!