碳事件“消耗”

发布于 2024-10-29 21:53:38 字数 1282 浏览 8 评论 0原文

我有一个问题,与此处描述的问题相反: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文