• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSCommandKeyMask being ignored in NSView subclasses
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSCommandKeyMask being ignored in NSView subclasses


  • Subject: NSCommandKeyMask being ignored in NSView subclasses
  • From: "Bruce Johnson" <email@hidden>
  • Date: Sun, 29 Jul 2007 17:27:20 -0600

In my NSView subclass I'm trying (and failing) to implement cmd-Z for undo
The NSCommandKeyMask in the keydown event is not being caught:
some code from the NSView Subclass:

- (BOOL) acceptsFirstResponder {
    return YES;
}

- (void) keyDown: (NSEvent *) event {
    unsigned int key = [event keyCode];
    unsigned int flags = [event modifierFlags];
    switch(key) {
        case 6: //"z"
            if (flags & NSCommandKeyMask) {
                printf("Undo last Action...\n"); fflush(stdout);
            }
     }

This isn't working... yet if I change it to this:

            if (flags & NSControlKeyMask) {
                printf("Undo last Action...\n"); fflush(stdout);
            }
This works fine, as does NSShiftKeyMask and NSAlternateKeyMask.

With NSCommandKeyMask, the application just beeps, and from what I
understand that means that the event is getting all the way up the responder
chain without getting handled.  It is as if NSCommandKeyMask is just being
ignored.

Now if do this in the same NSView subclass:
- (void)flagsChanged: (NSEvent *)theEvent {
    if ([theEvent modifierFlags] & NSCommandKeyMask) {
        printf("Window view NSCommandKeyMask\n"); fflush(stdout);
    }
}
It works just fine, the NSCommandKeyMask is caught and handled, in this case
the printf statement is executed.

I'm not sure what to make of it.  Any ideas would be appreciated.

Thank you.
--
----
Bruce Johnson
email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSCommandKeyMask being ignored in NSView subclasses
      • From: Andrew Farmer <email@hidden>
  • Prev by Date: Re: Values set in awakeFromInsert have gone missing.
  • Next by Date: Re: NSCommandKeyMask being ignored in NSView subclasses
  • Previous by thread: Re: NSLevelIndicator and mouse clicks
  • Next by thread: Re: NSCommandKeyMask being ignored in NSView subclasses
  • Index(es):
    • Date
    • Thread