Re: How to make NSImageView respond to keyboard events?
Re: How to make NSImageView respond to keyboard events?
- Subject: Re: How to make NSImageView respond to keyboard events?
- From: Laurent Bertacchini <email@hidden>
- Date: Sat, 15 May 2004 09:07:42 +0200
On May 14, 2004, at 8:09 PM, Peter Wollschlaeger wrote:
Am 14.05.2004 um 18:32 schrieb matt neuburg:
On Thu, 13 May 2004 23:25:57 +0200, Laurent Bertacchini
<email@hidden> said:
I'm writing a small picture viewer, and I use a subclass of
NSImageView
to display the pictures. Everything works fine except that on some
occasions (ex. full screen, ...) I'd like it to respond to keyboard
events. I tried overriding - (BOOL)acceptsFirstResponder, -
(BOOL)becomeFirstResponder, and - (BOOL)resignFirstResponder, so that
they return YES, but it doesn't seem to be enough (I only get a beep
when I press a key). I know that if I pass YES to setEditable, the
keyboard events will be parsed, but it will also trigger the drag &
drop feature, and I don't want that.
So, any ideas?
On my machine, using an NSImageView subclass in a project where this
is the
only code in the entire project, this works just fine:
#import "MyImageView.h"
@implementation MyImageView
- (void)keyDown:(NSEvent *)theEvent {
NSLog(@"here"); // this works
}
@end
This suggests that the ...FirstResponder stuff is a red herring.
Perhaps
you've merely forgotten to set the image view in Interface Builder to
be
your subclass...? m.
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
AppleScript: the Definitive Guide! NOW SHIPPING...! (Finally.)
http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
Here come code showing more details:
- (void)keyDown:(NSEvent *)evt {
NSString *keyChar = [evt characters];
if ( [keyChar isEqualToString:@"c"] ) {
[bp removeAllPoints];
[self setNeedsDisplay:YES];
}
}
Peter
This is confusing. I still cannot make it work, despite your answers.
Here is a step by step description of a test I just did:
- Create a new Cocoa Application in XCode,
- Open MainMenu.nib in Interface Builder,
- Subclass NSImageView -> MyImageView,
- Put an NSImageView on the window,
- Set the Custom Class of this NSImageView to MyImageView,
- Set the initialFirstResponder of the Window to the image view (whose
class is now MyImageView),
- Create the files for MyImageView,
- Back in XCode, I add this to the implementation file:
- (void)keyDown:(NSEvent *)theEvent
{
NSLog (@"Hi!");
}
- (BOOL)acceptsFirstResponder
{
return YES;
}
- (BOOL)becomeFirstResponder
{
return YES;
}
- (BOOL)resignFirstResponder
{
return YES;
}
- Build & Run the app
When I hit a key (any key), I only get a beep.
Did I miss something?
Laurent
_______________________________________________
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.