• 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: Capturing keydown events in an NSImageView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Capturing keydown events in an NSImageView?


  • Subject: Re: Capturing keydown events in an NSImageView?
  • From: Brent Gulanowski <email@hidden>
  • Date: Fri, 25 Jun 2004 13:14:40 -0400

On Fri, 25 Jun 2004 11:55:10 -0400, Jerry LeVan <email@hidden> wrote:
>
> Hello,
>
> I am trying to capture keydown events for an ImageView.
>
> I have subclassed NSImageView ....
> --------
> #import <Cocoa/Cocoa.h>
>
> @interface KeyImageView : NSImageView
> {
> IBOutlet id theController; // provides access to main controller
> object
> }
>
> -(BOOL)acceptsFirstResponder;
> -(BOOL)resignFirstResponder;
> -(BOOL)becomeFirstResponder;
> -(void)keyDown:(NSEvent*)theEvent;
>
> @end
>
> -------------
> #import "KeyImageView.h"
>
> @implementation KeyImageView
> -(BOOL)acceptsFirstResponder
> {
> NSLog(@"Accepting First Responder");
> return YES;
> }
>
> -(BOOL)resignFirstResponder
> {
> NSLog(@"Resigned First Responder");
> return YES;
> }
>
> -(BOOL)becomeFirstResponder
> {
> NSLog(@"Become First Responder");
> }
>
> -(void)keyDown:(NSEvent*)theEvent
> {
> NSLog(@"Key down: %@",theEvent);
> }
>
> @end
> --------
>
> The only message I get on the console is the Accept message
> the Become message never fires and key strokes always get
> the "bell".
>
> What am I missing here?
>
> Thanks,
>
> Jerry
> _______________________________________________
> cocoa-dev mailing list | email@hidden
> Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
>
>

That's all good, but you also have to make that view the first
responder. I haven't dealt with this question in two years, but then I
had to send the window a makeFirstResponder: message with the view as
the argument. There's an outlet for first responder in NSWindow and
you can connect it in IB, but I don't remember that doing what I
wanted.

You can tell if your view is not getting set as first responder if the
behaviour you want happens after you click the view with the mouse.

Cheers,

Brent
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Capturing keydown events in an NSImageView?
      • From: Jerry LeVan <email@hidden>
References: 
 >Capturing keydown events in an NSImageView? (From: Jerry LeVan <email@hidden>)

  • Prev by Date: Re: Getting mainMenu raises exception
  • Next by Date: Re: Getting mainMenu raises exception
  • Previous by thread: Capturing keydown events in an NSImageView?
  • Next by thread: Re: Capturing keydown events in an NSImageView?
  • Index(es):
    • Date
    • Thread