碳事件“消耗”
我有一个问题,与此处描述的问题相反:cocoa-global-shortcuts。示例:当我每次按“a”时将“a”键指定为快捷键(不带修饰符)时,我的回调就会触发,但其他应用程序不会按“a”:TextEdit、XCode 等。我不想“消费”该事件。 这是代码:
EventTypeSpec eventTypePressed = { kEventClassKeyboard, kEventHotKeyPressed };
InstallApplicationEventHandler(&HotKeyPressedHandler, 1, &eventTypePressed, self, NULL);
EventTypeSpec eventTypeReleased = { kEventClassKeyboard, kEventHotKeyReleased };
InstallApplicationEventHandler(&HotKeyReleasedHandler, 1, &eventTypeReleased, self, NULL);
EventHotKeyID eventHotKeyID = { 'htky', 1 };
RegisterEventHotKey(shortcut.code, shortcut.flags, eventHotKeyID, GetApplicationEventTarget(), 0, &_eventHotKeyRef);
OSStatus HotKeyPressedHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData) {
ShortcutHandler* handler = userData;
[handler.delegate keyWasPressed:handler];
return CallNextEventHandler(nextHandler, theEvent);
}
OSStatus HotKeyReleasedHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData) {
ShortcutHandler* handler = userData;
[handler.delegate keyWasReleased:handler];
return CallNextEventHandler(nextHandler, theEvent);
}
谢谢!
I have a problem, which is the opposite to problem described here: cocoa-global-shortcuts. Example: when I assigning "a" key as shortcut (without modifiers) every time I press "a" my callback fired, but other applications don't get "a" press: TextEdit, XCode, etc. I don't want to "consume" the event.
Here is the code:
EventTypeSpec eventTypePressed = { kEventClassKeyboard, kEventHotKeyPressed };
InstallApplicationEventHandler(&HotKeyPressedHandler, 1, &eventTypePressed, self, NULL);
EventTypeSpec eventTypeReleased = { kEventClassKeyboard, kEventHotKeyReleased };
InstallApplicationEventHandler(&HotKeyReleasedHandler, 1, &eventTypeReleased, self, NULL);
EventHotKeyID eventHotKeyID = { 'htky', 1 };
RegisterEventHotKey(shortcut.code, shortcut.flags, eventHotKeyID, GetApplicationEventTarget(), 0, &_eventHotKeyRef);
OSStatus HotKeyPressedHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData) {
ShortcutHandler* handler = userData;
[handler.delegate keyWasPressed:handler];
return CallNextEventHandler(nextHandler, theEvent);
}
OSStatus HotKeyReleasedHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData) {
ShortcutHandler* handler = userData;
[handler.delegate keyWasReleased:handler];
return CallNextEventHandler(nextHandler, theEvent);
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论