• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Keyboard events in an NSTextEntry
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Keyboard events in an NSTextEntry
      • From: Kyle Wheeler <email@hidden>
    • Re: Keyboard events in an NSTextEntry
      • From: Douglas Davidson <email@hidden>
References: 
 >Keyboard events in an NSTextEntry (From: Kyle Wheeler <email@hidden>)

  • Prev by Date: Re: NSTabView: VerticalTabs: when?
  • Next by Date: Re: idle waste
  • Previous by thread: Keyboard events in an NSTextEntry
  • Next by thread: Re: Keyboard events in an NSTextEntry
  • Index(es):
    • Date
    • Thread