即使Xcode 7中没有弃用CGEventCreateMouseEvent
,我也会收到错误
No matching function for call to 'CGEventCreateMouseEvent'
请找到适用于Xcode 6(SDK OSX 10.10)的代码
-(void)sendMouseClick:(CGMouseButton)mouseBtn value:(uint32_t)value
{
int mouseEvent = 0;
if(mouseBtn == kCGMouseButtonLeft && value == 1) //left btn down
{
mouseEvent = kCGEventLeftMouseDown;
}
else if (mouseBtn == kCGMouseButtonLeft && value == 0) //left btn up
{
mouseEvent = kCGEventLeftMouseUp;
}
else if (mouseBtn == kCGMouseButtonRight && value == 1) //Right btn down
{
mouseEvent = kCGEventRightMouseDown;
}
else if (mouseBtn == kCGMouseButtonRight && value == 0) //Right btn up
{
mouseEvent = kCGEventRightMouseUp;
}
if(mouseEvent != 0) // a valid mouse event
{
CGEventRef ourEvent = CGEventCreate(NULL);
NSPoint mouseLoc = CGEventGetLocation(ourEvent); //get current mouse position
CGEventRef mouseClick = CGEventCreateMouseEvent(
NULL,
mouseEvent,
mouseLoc,
mouseBtn
);
CGEventPost(kCGHIDEventTap, mouseClick);
}
}
我尝试导入<CoreGraphics/CGEvent.h>
,但没有任何区别。知道发生了什么吗?
答案 0 :(得分:0)
我发现SDK 10.11之后存在类型不匹配。
更改,
int mouseEvent = 0
到
CGEventType mouseEvent = kCGEventNull;
解决了这个问题。