Re: Accepting and Responding to Keystrokes
Re: Accepting and Responding to Keystrokes
- Subject: Re: Accepting and Responding to Keystrokes
- From: Jens Alfke <email@hidden>
- Date: Thu, 21 Jan 2010 16:35:19 -0800
On Jan 20, 2010, at 8:30 PM, Evan Schoenberg wrote:
> I copied the keyDown method from Cocoa in a Nutshell, by the way. Needless to say, I don't really understand it. Basically, I would love it if somebody could help me to get this program to work, because as of yet I have not gotten anything to respond to keystrokes. I believe that I need to make Input the First Responder, but I'm not sure about that and I don't know how to anyway...
You also need to tell Cocoa that your view can accept keyboard focus:
- (BOOL)canBecomeKeyView {
return YES;
}
And in your nib you want to wire the window's "initialKeyView" outlet to your view, so it'll be key by default.
Finally, The keyDown: method increases the length value, but it doesn't trigger a redraw of the view so this won't have any visible effect. After increasing length you need to call
[self setNeedsDisplay: YES];
which tells the window that your view should be redrawn ASAP.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden