Re: How to check for Arrow Key Down Event in a View?
Re: How to check for Arrow Key Down Event in a View?
- Subject: Re: How to check for Arrow Key Down Event in a View?
- From: Henry McGilton <email@hidden>
- Date: Tue, 18 Mar 2003 17:18:53 -0800
On Tuesday, March 18, 2003, at 01:42 PM, Umed Zokirov wrote:
* How to check for Arrow Key Down Event in a View?
* I.e, what event masks to check for?
You do not check for any event masks. The arrow keys are
specific characters.
* Do I have to override the keyDown method?
Yes, you must override keyDown. Your code will look something
like this:
- (void)keyDown:(NSEvent *)theEvent
{
NSString *characters = [theEvent characters];
int key = [characters characterAtIndex: 0];
if (key == NSUpArrowFunctionKey) {
; // do your up arrow code
} else if (key == NSDownArrowFunctionKey) {
; // do your down arrow code
} else if (key == NSLeftArrowFunctionKey) {
; // do your left arrow code
} else if (key == NSRightArrowFunctionKey) {
; // do your right arrow code
}
You might also want to check the documentation (and possibly
the Cocoa Programming book) to determine the combination of
key window and first responder that will enable you to process
keyDown events correctly. I know that the view in which this
code lives returns YES from the overridden methods
- (BOOL)acceptsFirstResponder and - (BOOL)becomeFirstResponder
For the purists out there, yes, I am aware that the line
getting the 'key' variable could be more rigourous and
robust, but if it does go 'bust' I will re-insert the 'ro'
part . . .
Cheers,
........ Henry
===============================+============================
Henry McGilton | Trilithon Software
Boulevardier, Java Composer | Seroia Research
-------------------------------+----------------------------
mailto:email@hidden |
http://www.trilithon.com
===============================+============================
_______________________________________________
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.