如何在按住Command键的情况下在NSView中检测keyUp :? [英] How do I detect keyUp: in my NSView with the Command key held?

查看:79
本文介绍了如何在按住Command键的情况下在NSView中检测keyUp :?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的NSView子类中,例如,键入Command + J时,我看到按下Command的 flagsChanged:,然后按下 J的keyDown: ...然后释放Command的 flagsChanged:。我从没见过J的 keyUp:

In my NSView subclass, when I type, for example, Command+J, I see the flagsChanged: for Command being pressed, then a keyDown: for J... and then the flagsChanged: for Command being released. I never see a keyUp: for J.

我尝试覆盖 performKeyEquivalent:,它看起来像我想要的,但是在 keyDown:

I tried overriding performKeyEquivalent:, which looked like it did what I want, however that gets sent before the keyDown:!

那么还有什么我想赶上 keyUp:事件吗?

So is there something else I'm missing to catch the keyUp: events?

没有示例程序时间,对不起。谢谢!

No sample program this time, sorry. Thanks!

推荐答案

前一段时间我也遇到了这个问题。问题似乎是NSApplication正在消耗Cmd密钥的keyUp(或flagsChanged)。

I also ran into this issue a while ago. The problem seems to be that NSApplication is eating up the keyUp (or flagsChanged) for the Cmd key.

我实际上发现了两个解决方案。
首先是覆盖NSApplication,如此处所述:

There are actually two solutions I found. The first is overriding NSApplication as also described here:

http://lists.apple.com/archives/cocoa-dev/2003/Oct/msg00442.html

另一种是做一些自己的逻辑来检测Cmd密钥的密钥,如下所述:

The other is to do some own logic to detect the key up of the Cmd key as described here:

Command-Key-Up可可

但是,第二个选项可能不起作用,因为您不想检测Cmd keyUp而是J keyUp。不过,第一种解决方案应该可以做到这一点。

However, this second option might not work as you don't want to detect the Cmd keyUp but rather the J keyUp. This should be possible with the first solution though.

这篇关于如何在按住Command键的情况下在NSView中检测keyUp :?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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