Cocoa 阻止CGEventCreateKeyboardEvent已按下修改器键
我正在使用Cocoa 阻止CGEventCreateKeyboardEvent已按下修改器键,cocoa,events,Cocoa,Events,我正在使用cgreventcreatekeyboardevent创建和cgreventpost在Mac上发布事件。以下代码适用于按“a”键 CGEventRef downEvent = CGEventCreateKeyboardEvent(NULL, 0, YES); CGEventPost(kCGHIDEventTap, downEvent); CFRelease(downEvent); 问题在于用户可能按下了修改键。例如,当用户在发送my keyboard事件时已按下Command键时,C
cgreventcreatekeyboardevent
创建和cgreventpost
在Mac上发布事件。以下代码适用于按“a”键
CGEventRef downEvent = CGEventCreateKeyboardEvent(NULL, 0, YES);
CGEventPost(kCGHIDEventTap, downEvent);
CFRelease(downEvent);
问题在于用户可能按下了修改键。例如,当用户在发送my keyboard事件时已按下Command键时,Command+a将被发送到活动应用程序,而不仅仅是字符a
有办法解决这个问题吗?我可以明确地说我想发布一个字符,忽略任何可能已经按下的(修改器)键。您是否尝试将事件的标志设置为
0
?没有尝试过,我想这不会有帮助,因为修改器键是由以前的事件设置的。不过值得一试。编辑:成功了,谢谢!