本文介绍了移动鼠标光标(Windows的SetCursorPos的OSX版本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我一直试图在Mac OSX El capitan 10.11.2上使用鼠标光标.我已经进行了一些挖掘,发现了许多不赞成使用的方法和一些新方法.尝试了许多示例,但到目前为止都没有奏效.

I've been trying to mouse my mouse cursor on Mac OSX El capitan 10.11.2. I've done some digging and found many ways some were deprecated and some were new. Tried many examples but none of them worked so far.

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

Here's what i've tried so far

CGWarpMouseCursorPosition(CGPointMake(200, 200));

这不起作用并返回0

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

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

CGWarp also returns 0 here(basically the same thing lel)

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

这来自apple.developer也不起作用.

This comes from apple.developer didn't work either.

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

IMPORTANT NOTE: i am working on a VMWare Virtual Machine.

我尝试了更多代码段,但是没有任何效果.

I've tried a few more code pieces but nothing is working.

推荐答案

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

You're looking for the event queue. Here are some sample calls in 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);

这篇关于移动鼠标光标(Windows的SetCursorPos的OSX版本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 10:05