NSCommandKeyMask being ignored in NSView subclasses
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