Re: Keyboard events in an NSTextEntry
Re: Keyboard events in an NSTextEntry
- Subject: Re: Keyboard events in an NSTextEntry
- From: Timothy Ritchey <email@hidden>
- Date: Thu, 28 Mar 2002 18:27:00 -0500
On Thursday, March 28, 2002, at 03:49 PM, Kyle Wheeler wrote:
I have an NSTextEntry (in an NSWindow) that I need to intercept some
keystrokes for - specifically, I want to intercept '=' and num-lock and
handle them myself (simulate clicking on specific buttons) but let the
rest of them go to the NSTextEntry. I've looked in the documentation
and online and there's no good, simple, example... can someone help me
out?
Do you mean an NSTextView? Here is a function I use to intercept tabs,
returns, shift-tabs, and arrow keys to change the cell I am editing in
the spreadsheet. Set yourself as the delegate of the NSTextView, and
implement this method in your delegate:
- (BOOL)textView:(NSTextView *)aTextView
doCommandBySelector:(SEL)aSelector
{
// check to see if we got a return or tab,
// or arrow and move accordingly
NSEvent *event = [NSApp currentEvent];
unsigned int modifier = [event modifierFlags];
unichar key = [[event characters] characterAtIndex:0];
if([event keyCode] == 48 && modifier & NSShiftKeyMask) {
// got a shift-tab key
newIndex = [newPos column] - 1;
if(newIndex < 0)
<SNIP>
} else if(key == NSUpArrowFunctionKey) {
newIndex = [newPos row] - 1;
if(newIndex < 0)
newIndex = 0;
[newPos setRow:newIndex];
} else {
return NO;
}
<SNIP>
return YES;
}
_______________________________________________
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.