• 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: Help with text input
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with text input


  • Subject: Re: Help with text input
  • From: Douglas Davidson <email@hidden>
  • Date: Fri, 30 Apr 2010 09:41:38 -0700

On Apr 30, 2010, at 9:32 AM, Charles Srstka wrote:

> On Apr 30, 2010, at 11:08 AM, Bill Appleton wrote:
>
>> don't i need to use interpretKeyEvents to gather the key events until
>> insertText is called?
>
> Yep, just do something like this:
>
> - (void)keyDown:(NSEvent *)theEvent {
>    [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
>    [NSCursor setHiddenUntilMouseMoves:YES]; // to make the cursor hide while you are typing like Mac users are used to
> }
>
> Then, you override insertText:replacementRange: to get text that should be typed. If you want to do something like the arrow keys, then override the various methods in NSResponder. For example, if the user hits the right arrow key, your object will get a -moveRight: message. If you do this, then your app will still work with custom key bindings the user has set up (since the text system is completely configurable). So say a user decides he wants his keypad to work like a PC with “Num Lock” off, and sets up his key bindings so that the 4, 8, 6, and 2 keys on the keypad map to the same methods that the arrow keys are bound to. In this case, your app will Just Work™ without even having to know about this user’s unusual setup.

Here is the normal sequence when a text-handling view receives key events:  the keyDown: method passes events to interpretKeyEvents:, which is where they enter key binding and input management.  They come out either as insertText: or as doCommandBySelector: (see NSResponder.h for these three methods).  insertText: will be used for text input, doCommandBySelector: with an appropriate selector for special keys like arrow keys.  The relevant selectors are mostly listed in NSResponder.h.  The default NSResponder implementation of doCommandBySelector: checks whether the receiver responds to the given selector, and if so calls it; otherwise it is passed on to the next responder's doCommandBySelector:.

Douglas Davidson

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Help with text input
      • From: Charles Srstka <email@hidden>
References: 
 >Help with text input (From: Bill Appleton <email@hidden>)
 >Re: Help with text input (From: Jens Alfke <email@hidden>)
 >Re: Help with text input (From: Charles Srstka <email@hidden>)
 >Re: Help with text input (From: Douglas Davidson <email@hidden>)
 >Re: Help with text input (From: Bill Appleton <email@hidden>)
 >Re: Help with text input (From: Shawn Erickson <email@hidden>)
 >Re: Help with text input (From: Bill Appleton <email@hidden>)
 >Re: Help with text input (From: Shawn Erickson <email@hidden>)
 >Re: Help with text input (From: Bill Appleton <email@hidden>)
 >Re: Help with text input (From: Charles Srstka <email@hidden>)

  • Prev by Date: Re: Help with text input
  • Next by Date: Re: Help with text input
  • Previous by thread: Re: Help with text input
  • Next by thread: Re: Help with text input
  • Index(es):
    • Date
    • Thread