Re: intercepting keydowns
Re: intercepting keydowns
- Subject: Re: intercepting keydowns
- From: Satoshi Matsumoto <email@hidden>
- Date: Sun, 03 Apr 2005 20:54:51 +0900
Hi Roland,
James Spencer's comment may be very helpful for you.
Thank you, James.
Sorry, I am not good at English. If you have any more uncertain things,
please refer to following documents.
for subclassing NSTextView
ADC Home > Reference Library > Documentation > Cocoa > User Experience >
Controls and Cells > Text Views > Introduction to Text Views
for subclassing NSApplication
ADC Home > Reference Library > Documentation > Cocoa > Objective-C Language
> Application Kit Reference for Objective-C >NSApplication Subclassing Notes
Satoshi
on 05.4.3 9:36 AM, Roland Silver at email@hidden wrote:
> 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.
>
>
>
>
>
>
>
>
>
> 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
>>
>>
>>
-----------------------------------------------------
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