我正在尝试使用C或C ++模拟鼠标移动和鼠标点击。
但遗憾的是,我没有找到任何相同的图书馆。
我见过windows.h(仅适用于Windows)和swinput(适用于Linux)
Mac上有类似的东西吗?
答案 0 :(得分:2)
CGPostMouseEvent
。你可以用
CGEventRef mouseDownEv = CGEventCreateMouseEvent (NULL,kCGEventLeftMouseDown,pt,kCGMouseButtonLeft);
CGEventPost (kCGHIDEventTap, mouseDownEv);
CGEventRef mouseUpEv = CGEventCreateMouseEvent (NULL,kCGEventLeftMouseUp,pt,kCGMouseButtonLeft);
CGEventPost (kCGHIDEventTap, mouseUpEv );
CGEventRef CGEventCreateMouseEvent(
CGEventSourceRef source, // The event source may be taken from another event, or may be NULL.
CGEventType mouseType, // `mouseType' should be one of the mouse event types.
CGPoint mouseCursorPosition, // `mouseCursorPosition' should be the position of the mouse cursor in global coordinates.
CGMouseButton mouseButton); // `mouseButton' should be the button that's changing state;
// `mouseButton' is ignored unless `mouseType' is one of
// `kCGEventOtherMouseDown', `kCGEventOtherMouseDragged', or `kCGEventOtherMouseUp'.
鼠标按钮0是鼠标上的主按钮。 鼠标按钮1是辅助鼠标按钮(右)。 鼠标按钮2是中央按钮,其余按钮是USB设备顺序。
kCGEventLeftMouseDown
kCGEventLeftMouseUp
kCGEventRightMouseDown
kCGEventRightMouseUp
kCGEventMouseMoved
kCGEventLeftMouseDragged
kCGEventRightMouseDragged
现在可以随时使用。
答案 1 :(得分:1)
我的建议是检查VNC的Mac端口是如何做到的。