Re: intercepting keydowns
Re: intercepting keydowns
- Subject: Re: intercepting keydowns
- From: Roland Silver <email@hidden>
- Date: Sat, 2 Apr 2005 17:36:03 -0700
Hi Satoshi,
Thanks for your email to me and the cocoa-dev list responding to my
question about intercepting keydowns.
I followed your advice in this way:
I started an Xcode Cocoa project called EmulatorExperiment.03, and
started up Interface Builder by double-clicking MainMenu.nib. I dragged
an NSTextView into the window, created a subclass MyTextView of
NSTextView, Instantiated it, created subfiles for it, and saved the
MainMenu.nib file.
Back in Xcode, I moved MyTextView.[hm] to the Classes group, and added
a keyDown override (whose declaration I got from the documentation for
NSResponder), to myTextView.m:
- (void)keyDown:(NSEvent *)theEvent {
NSLog(@"keyDown:theEvent = %@", theEvent);
}
figuring that if my keyDown method got called, I would see evidence of
it in the Run Log.
I built the project, ran it, and successfully entered a few characters
into the text view -- but no evidence of the overriding keyDown being
called appeared in the Run Log.
I then followed your further advice by subclassing NSApplication as
MyApplication, creating files for it (but not instantiating it: IB
won't let me), and saving the MainMenu.nib file.
Back in Xcode, I added a sendEvent override to MyApplication.m:
- (void)sendEvent:(NSEvent *)theEvent {
NSLog(@"sendEvent:theEvent = %@", theEvent);
}
I haven't done anything else in IB, like dragging something to
something else to establish delegation, outlets, or actions.
As before, I built the project, ran it, and successfully entered a few
characters into the text view -- but no evidence of the overriding
keyDown or sendEvent being called appeared in the Run Log:
[Session started at 2005-04-02 17:24:18 -0700.]
Executable “EmulatorExperiment.03” has exited with status 0.
I'm appending the files main.m, MyApplication.[hm], MyTextView.[hm],
and MainMenu.nib, hoping that you can help me to get this program to
work.
Attachment:
main.m
Description: Binary data
/* MyApplication */
#import <Cocoa/Cocoa.h>
@interface MyApplication : NSApplication
{
}
@end
Attachment:
MyApplication.m
Description: Binary data
/* MyTextView */
#import <Cocoa/Cocoa.h>
@interface MyTextView : NSTextView
{
}
@end
Attachment:
MyTextView.m
Description: Binary data
Attachment:
MainMenu.nib.zip
Description: Zip archive
Thanks for your advice and support,
Rollo (Roland) Silver <email@hidden>
----------------------------------------------------------
On Apr 2, 2005, at 1:35 PM, Satoshi Matsumoto wrote:
on 05.4.3 1:59 AM, Roland Silver at email@hidden wrote:
I have a simple Cocoa application with a controller and a window with
an NSTextView. I want to intercept keydown events on their way to the
text view, process them with a function or method, and send a possibly
different keydown event on to the text view.
Nothing I try works.
Any suggestions?
Subclass NSTextView and override following method.
- (void)keyDown:(NSEvent *)theEvent
And if you wish to intercept all key events including all menu short
cuts,
subclass NSApplication and override following method.
- (void)sendEvent:(NSEvent *)theEvent
Satoshi
-----------------------------------------------------
Satoshi Matsumoto <email@hidden>
816-5 Odake, Odawara, Kanagawa, Japan 256-0802
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden