Re: Arrow keys
Re: Arrow keys
- Subject: Re: Arrow keys
- From: Andy Lee <email@hidden>
- Date: Tue, 19 Mar 2002 21:00:10 -0500
At 3:11 PM -0700 3/19/02, email@hidden wrote:
>
Using the Interface Builder, is it possible to connect a button with an arrow key? If that isn't possible, can I add some code into my cocoa app which will then call the same functions as the associated arrow buttons?
Timothy Wood posted a way to do something similar in code, using the unichar type. He was answering a question about [NSWindow -keyDown:], but I suspect you can use similar logic to make a button behave. Here's what Tim wrote (including email headers, in case you want to search the archives for the thread):
At 1:30 PM -0800 3/10/02, Timothy J. Wood wrote:
>
Subject: Re: Handling arrow key events
>
Cc: <email@hidden>
>
To: Jonathan Jackel <email@hidden>
>
From: "Timothy J. Wood" <email@hidden>
>
Sender: email@hidden
>
Date: Sun, 10 Mar 2002 13:30:39 -0800
>
>
NSString *characters;
>
unsigned int characterIndex, characterCount;
>
>
characters = [event characters];
>
characterCount = [characters count];
>
for (characterIndex = 0; characterIndex < characterCount; characterIndex++) {
>
UniChar c;
>
>
c = [characters characterAtIndex: characterIndex];
>
switch (c) {
>
case NSLeftArrowFunctionKey:
>
....
>
break;
>
... other cases ...
>
}
>
}
>
>
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.
>
>
-tim
>
>
>
On Sunday, March 10, 2002, at 12:43 PM, Jonathan Jackel wrote:
>
>
>How do I handle arrow keys in a keydown: handler? Handling the delete key
>
>is easy. I do:
>
>
>
>if ([[event characters] isEqualToString:@"\177"])
>
>
>
>Works great. Arrow keys return what appears to be a similar control
>
>character, e.g., "\uf702" for left arrow, but when I put that in the if
>
>statement I get a warning "unknown escape sequence '\u'" and it never comes
>
>up true. I see a reference to NSLeftArrowFunctionKey in the
>
>NSEventConstants, but I am not grasping how to make it work.
>
>
>
>Jonathan Jackel
_______________________________________________
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.