Re: Right arrow keypress == enter keypress in NSTableView subclass?
Re: Right arrow keypress == enter keypress in NSTableView subclass?
- Subject: Re: Right arrow keypress == enter keypress in NSTableView subclass?
- From: Clark Cox <email@hidden>
- Date: Wed, 28 Jul 2004 14:12:47 -0400
On 7 28, 2004, at 11:46, John C. Warner wrote:
>
I have a NSTableView subclass in my app that implements a little
>
favorites list for users to keep often-used files in. I have keyboard
>
navigation working - up/down arrow, and return/enter to open the file,
>
but pressing the right arrow key also launches the file. This isn't
>
unwelcome behaviour - it was the next thing on my to do list - but I'd
>
like to know why it's happening, and if I should rely on it. Is this
>
just the way NSTableView works?
>
>
Here's my view's keyDown method:
>
>
-(void)keyDown:(NSEvent *)theEvent
>
{
>
char keyChar = [[theEvent characters] characterAtIndex:0];
Several problems with the previous line.
First: [theEvent characters] could be zero characters long. Your
program will throw an exception in such a case.
Second: -characterAtIndex: returns a unichar.
NSRightArrowFunctionKey is 0xF703, which when you assign it to an 8-bit
char, becomes 0x03 (which is equal to NSEnterCharacter)
You will observe the same behavior if you press the "F10" key, as
NSF10FunctionKey (0xF70D) will be truncated to 0x0D
(NSCarriageReturnCharacter).
>
>
if (keyChar == NSEnterCharacter || keyChar ==
>
NSCarriageReturnCharacter)
>
{
>
[[self dataSource] openBookmark:self];
>
}
>
else
>
{
>
[super keyDown:theEvent];
>
}
>
}
--
Clark S. Cox III
email@hidden
http://www.livejournal.com/users/clarkcox3/
http://homepage.mac.com/clarkcox3/
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.