• 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
Keypress problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Keypress problems


  • Subject: Keypress problems
  • From: Alex Reynolds <email@hidden>
  • Date: Wed, 23 May 2007 02:57:16 -0400

I have a problem with subclasses of NSWindowController and NSWindow not passing Apple-key combinations to the application.

My application controller loads the MainMenu.nib file (which contains the menu). My application controller instantiates the NSWindowController subclass. This NSWindowController subclass then instantiates my custom NSWindow.

As an example of my problem, I would press Apple-W to close the custom subclassed window, but the application does not respond.

My NSWindow subclass is able "hear" key events. I have the following code to prove it:

- (BOOL) performKeyEquivalent:(NSEvent *) event
{
NSString *keyEquiv = [event charactersIgnoringModifiers];
unsigned int eventFlags = ([event modifierFlags] & NSDeviceIndependentModifierFlagsMask);


NSLog(@"keyEvent: %@", keyEquiv);
NSLog(@"characters: %@", [event characters]);
NSLog(@"charactersIgnoringModifiers: %@", keyEquiv);
NSLog(@"deviceIndependentModifierFlags: %d", eventFlags);
NSLog(@"NSControlKeyMask: %d, %d", ((eventFlags & NSControlKeyMask) ! = 0), NSControlKeyMask);
NSLog(@"NSAlternateKeyMask: %d, %d", ((eventFlags & NSAlternateKeyMask) != 0), NSAlternateKeyMask);
NSLog(@"NSShiftKeyMask: %d, %d", ((eventFlags & NSShiftKeyMask) != 0), NSShiftKeyMask);
NSLog(@"NSAlphaShiftKeyMask: %d, %d", ((eventFlags & NSAlphaShiftKeyMask) != 0), NSAlphaShiftKeyMask);
NSLog(@"NSCommandKeyMask: %d, %d", ((eventFlags & NSCommandKeyMask) ! = 0), NSCommandKeyMask);


	return YES;
}

But keypresses are just not passed up to the application.

Do I really have to do something like:

if ( (((eventFlags & NSCommandKeyMask) != 0) == 1) && ([event keyCode] == 12) ) // 'q'
{
[ [NSApplication sharedApplication] sendAction:@selector(terminate:) to:[NSApplication sharedApplication] from:self];
}


to quit the application, as well as equivalent actions for every single possible key combination?

Or is there an easier way to pass keypresses up to the (menu) actions in the MainMenu.nib file?

Thanks,
Alex
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Prev by Date: releasing NSProgressIndicator
  • Next by Date: Re: releasing NSProgressIndicator
  • Previous by thread: Re: releasing NSProgressIndicator
  • Next by thread: Disabling items of "Input Menu"
  • Index(es):
    • Date
    • Thread