gpt4 book ai didi

c++ - 移动鼠标光标(Windows 的 SetCursorPos 的 OSX 版本)

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:15:10 32 4
gpt4 key购买 nike

我一直在尝试将鼠标光标置于 Mac OSX El capitan 10.11.2 上。我做了一些挖掘,发现有很多方法有些已被弃用,有些是新的。尝试了很多例子,但到目前为止都没有成功。

这是我到目前为止尝试过的方法

CGWarpMouseCursorPosition(CGPointMake(200, 200));

这不起作用并返回 0

CGPoint warpPoint = CGPointMake(42, 42);
CGWarpMouseCursorPosition(warpPoint);
CGAssociateMouseAndMouseCursorPosition(true);

CGWarp 在这里也返回 0(基本上是一样的东西 lel)

CGDisplayHideCursor (kCGNullDirectDisplay);
CGAssociateMouseAndMouseCursorPosition (false);
CGDisplayMoveCursorToPoint (kCGDirectMainDisplay, CGPointMake(200, 200));
CGAssociateMouseAndMouseCursorPosition (true);
CGDisplayShowCursor (kCGNullDirectDisplay);

这来自 apple.developer 也没有工作。

重要说明:我正在使用 VMWare 虚拟机。

我尝试了更多的代码片段,但没有任何效果。

最佳答案

您正在寻找事件队列。以下是 Objective-C 中的一些示例调用:

CGPoint startButton = CGPointMake(self.gameOrigin.x + 35, self.gameOrigin.y + 340);
CGEventRef click_down = CGEventCreateMouseEvent(
NULL, kCGEventLeftMouseDown,
startButton,
kCGMouseButtonLeft
);
CGEventRef click_up = CGEventCreateMouseEvent(
NULL, kCGEventLeftMouseUp,
startButton,
kCGMouseButtonLeft
);
CGEventPost(kCGHIDEventTap, click_down);
CGEventPost(kCGHIDEventTap, click_up);
CFRelease(click_up);
CFRelease(click_down);

关于c++ - 移动鼠标光标(Windows 的 SetCursorPos 的 OSX 版本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34550223/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com