Re: Arrow keys
Re: Arrow keys
- Subject: Re: Arrow keys
- From: email@hidden
- Date: Tue, 19 Mar 2002 20:20:06 -0800
Timothy Wood posted a way to do something similar in code, using the
unichar type.
This is all well and good, except for:
There is no guarantee that the event will have only one character, so
you should probably make sure that you handle all of them. Obviously
this could be simplified if you want to assume that there is only one
character.
I meant to comment on this the first time, but I think I forgot. I
believe this is somewhat misleading. At the time keyDown: is called,
you're only dealing with a single keypress. Multiple keys don't get
buffered together until you're dealing with interpretKeyEvents:, which
gets passed an array of NSEvents. The only reason NSEvent returns an
NSString* instead of a unichar is that some single keypresses could
generate multiple characters, as in a composed character sequence. When
dealing with things like finding out whether arrow keys have been
pressed, I believe this is a total non-issue. When I write keyDown:
code, I generally do something like "if (([characters length] == 1) &&
([characters characterAtIndex:0] == NSLeftArrowFunctionKey)) ..." I
have never seen this to fail, and I believe I got this pattern straight
of the AppKit code back when I was learning Obj-C at NeXT. Which is not
to say that I'm right, but merely to say that if I'm wrong, someone else
is to blame. ;->
Now that I've put my neck on the line, would someone care to chop my
head off? My track record for correct answers isn't so good today... :->
Ben Haller
Stick Software
_______________________________________________
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.