• 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
Re: Getting keyDowns
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting keyDowns


  • Subject: Re: Getting keyDowns
  • From: Rosyna <email@hidden>
  • Date: Sun, 26 Aug 2001 23:49:46 -0700

Thanks, this works nicely for the most part. The only problem is when I press something like Command-S it still gets blocked, despite the docs saying when a menu item is disabled it doesn't respond to key equivalents.

From NSMenu.html:

"(A disabled menu item has a gray title and does not respond to mouse clicks or key equivalents.)"

Beeping is still responding to key equivalents IMHO.

Ack, at 8/27/01, Ondra Cada said:

Nope, keyDowns don't go to delegate (see the NSResponder.html, the event processing is described there in details; no <<<forthcomings>>> there!). If you do need to catch them, you have to subclass (or category) a NSWindow. The following trivial sample should work (it does in MOSXS1, not tested in OSX):

(i) make a new application project, make sure it contains at least one window displayed automatically at startup (should be the default behaviour without any coding);
(ii) into any source file (the "...main.m" is sufficient, placement unimportant) add

@implementation NSWindow (Test)
-(void)keyDown:(NSEvent*)evt {
NSLog(@"window got %@",[evt characters]);
}
@end

Build and run, activate window, type a few keys, see the console. Note that (exactly as documented!) views' keyDown: take precedence before the window's one -- if you try to place a textfield (or any other view which reads keys) into the window, it would get keys, and nothing will be logged.

(In practice, you would rather subclass the window, of course.)

--
Sincerely,
Rosyna Keller
Technical Support/Holy Knight/Always needs a hug

Unsanity: Unsane Tools for Insane People


  • Follow-Ups:
    • Re: Getting keyDowns
      • From: Ondra Cada <email@hidden>
References: 
 >Re: Getting keyDowns (From: "John C. Randolph" <email@hidden>)
 >Re: Getting keyDowns (From: Rosyna <email@hidden>)
 >Re: Getting keyDowns (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Bug in Project Builder? And IB???
  • Next by Date: Re: Docs, questions and stuff
  • Previous by thread: Re: Getting keyDowns
  • Next by thread: Re: Getting keyDowns
  • Index(es):
    • Date
    • Thread