andlabs
andlabs

Reputation: 11578

How do I detect keyUp: in my NSView with the Command key held?

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.

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

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

No sample program this time, sorry. Thanks!

Upvotes: 1

Views: 877

Answers (1)

guitarflow
guitarflow

Reputation: 2970

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.

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

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

Command-Key-Up Cocoa

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.

Upvotes: 2

Related Questions