CGEventTapCreate()调用的问题 [英] Issue with CGEventTapCreate() call

查看:485
本文介绍了CGEventTapCreate()调用的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用以下代码注册全局关键事件:

  void function()
{
CFMachPortRef keyUpEventTap = CGEventTapCreate(kCGHIDEventTap,kCGHeadInsertEventTap,kCGEventTapOptionListenOnly,CGEventMaskBit(kCGEventKeyUp),& keyUpCallback,NULL);


CFRunLoopSourceRef keyUpRunLoopSourceRef = CFMachPortCreateRunLoopSource(NULL,keyUpEventTap,0);
CFRelease(keyUpEventTap);

CFRunLoopAddSource(CFRunLoopGetCurrent(),keyUpRunLoopSourceRef,kCFRunLoopDefaultMode);
CFRelease(keyUpRunLoopSourceRef);
}

应用程序在执行CFMachPortCreateRunLoopSource()调用时崩溃。我认为崩溃是因为CGEventMaskBit( kCGEventKeyUp )当我创建一个事件点击。



但是如果我创建事件点击使用 CGEventTapCreate(kCGHIDEventTap,kCGHeadInsertEventTap,kCGEventTapOptionListenOnly,CGEventMaskBit(kCGEventFlagsChanged),& keyUpCallback,NULL),应用程序工作正常。它不会崩溃。我按任何修改键时收到回调。



谢谢,



Dheeraj。

解决方案

我找到此链接上此问题的修复: / p>

http://www.cocoabuilder.com/archive/cocoa/242438-trouble-with-event-taps.html


I'm trying to register for global key events using this code :

void function()
{
    CFMachPortRef keyUpEventTap = CGEventTapCreate(kCGHIDEventTap,kCGHeadInsertEventTap,kCGEventTapOptionListenOnly,CGEventMaskBit(kCGEventKeyUp),&keyUpCallback,NULL);


CFRunLoopSourceRef keyUpRunLoopSourceRef = CFMachPortCreateRunLoopSource(NULL, keyUpEventTap, 0);
    CFRelease(keyUpEventTap);

    CFRunLoopAddSource(CFRunLoopGetCurrent(), keyUpRunLoopSourceRef, kCFRunLoopDefaultMode);
    CFRelease(keyUpRunLoopSourceRef);
}

The application crashes while executing CFMachPortCreateRunLoopSource() call. I think the crash is because of CGEventMaskBit(kCGEventKeyUp) when I create an event tap.

But if I create event tap using CGEventTapCreate(kCGHIDEventTap,kCGHeadInsertEventTap,kCGEventTapOptionListenOnly,CGEventMaskBit(kCGEventFlagsChanged),&keyUpCallback,NULL), the application works fine. It does not crash. I'm getting callbacks when any modifier key is pressed. But I need to get callbacks for delete key pressed.

Any ideas?

Thanks,

Dheeraj.

解决方案

I found the fix for this issue on this link :

http://www.cocoabuilder.com/archive/cocoa/242438-trouble-with-event-taps.html

这篇关于CGEventTapCreate()调用的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆