Re: Getting keyDowns
Re: Getting keyDowns
- Subject: Re: Getting keyDowns
- From: Ondra Cada <email@hidden>
- Date: Mon, 27 Aug 2001 01:22:37 +0200
Rosyna,
>
>>>>> Rosyna (R) wrote at Sun, 26 Aug 2001 15:33:01 -0700:
R> I know it is getting some sort of event as it responds to
R> windowWillClose and when I enable the text field, I can type it in.
R> But neither mouseDown or keyDown get called. KeyHandler is now a
R> subclass of NSResponder as well.
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.)
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc