CGEventRef和CGEventCreateKeyboardEvent问题

时间:2015-07-13 05:22:20

标签: objective-c xcode macos

我在Mac OS上有以下Objective-c代码:

@import CoreGraphics;

CGEventRef event1, event2;
event1 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)56, true);
event2 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)6, true);

产生错误:

Redefinition of 'event1' with a different type: 'int' vs 'CGEvenRef' (aka 'struct ++CGEvent *')
Type specifier missing, defaults to 'int'

Redefinition of 'event2' with a different type: 'int' vs 'CGEvenRef' (aka 'struct ++CGEvent *')
Type specifier missing, defaults to 'int'

我理解其中的一些并查看了文档,并且相信我的代码应该可行,但它并没有。有什么建议?我正在使用Xcode,我的Mac OS和Xcode版本是最新的。

我甚至粘贴了这个标记为正确的问题的代码,但它也会出错:

How to paste programatically on OS X?

1 个答案:

答案 0 :(得分:0)

重新检查您的代码库,看看您是否在其他地方定义了event1event2

此代码看起来很好。另一个尝试是使用一些其他变量名称而不是event1event2