简体   繁体   English

CGEventTap + NSStatusItem 问题

[英]CGEventTap + NSStatusItem problems

My application has a NSStatusItem and an CGEventTap.我的应用程序有一个 NSStatusItem 和一个 CGEventTap。 Whenever you click the NSStatusItem it hangs for a few seconds before the Menu or the NSStatusitem itself accepts events again.每当您单击 NSStatusItem 时,它会在 Menu 或 NSStatusitem 本身再次接受事件之前挂起几秒钟。

After that the event tap is disabled, most likely thanks to the status item.之后,事件点击被禁用,很可能是由于状态项。 Why are these 2 colliding?为什么这两个会发生碰撞? The event tap is only listening and I have no issues at all with other applications.事件水龙头只是在听,我对其他应用程序没有任何问题。

eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 1,CGEventMaskBit(NX_SYSDEFINED) | (1 << kCGEventKeyDown) | (1 << kCGEventKeyUp) | (1 << kCGEventMouseMoved), printEventCallback, NULL);

The third argument of the function should be 1, was still 0 in the actual code. function的第三个参数应该是1,实际代码中还是0。 If its 1 then its a Listen CGEventTap and thus cannot modify or filter the event.如果它为 1,那么它是一个 Listen CGEventTap,因此无法修改或过滤事件。

This also fixes an issue the event tap could have together with the game Minecraft.这也解决了事件点击可能与游戏 Minecraft 一起出现的问题。 So if your CGEventTap only needs to listen and not filter make sure that that argument is set to 0x1 or 1因此,如果您的 CGEventTap 只需要监听而不需要过滤,请确保该参数设置为 0x1 或 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM