• 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: Custom NSTextField & keyDown:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom NSTextField & keyDown:


  • Subject: Re: Custom NSTextField & keyDown:
  • From: Douglas Davidson <email@hidden>
  • Date: Mon, 23 Sep 2002 11:59:20 -0700

On Saturday, September 21, 2002, at 08:26 PM, Ryan McGann wrote:

I'm writing an application which allows the user to assign custom key combinations to various tasks. In order to assign the "hotkey" the user enters it in an NSTextField. I want the text field to show all the modifiers and characters that were used in the hotkey, so pressing command-shift-five displays cmd-shift-5, not cmd-shift-%.

Several problems:
- My subclass of NSTextField is definitely being instantiated (its awakeFromNib method is called), but its keyDown: method is not being called. If I change it to keyUp: I get called, but this is too late.
- I need to convert the key code into a character. In Carbon I can call KeyTranslate. What's the similar functionality in Cocoa?
- I need to capture the key strokes before command key binding is doneI want the user to be able to use the command key as a modifier key.
- How do I stop the caret from blinking, without stopping the NSTextField from becoming the first responder?

NSTextField and other controls don't handle their own text input. When a control starts editing, an NSTextView, called the field editor, is assigned to it and placed over it, and it handles the text input. The field editor is normally shared among the controls in a window, since only one of them will be editing at one time. You can supply your own custom field editor if you wish.

Normally when people talk about overriding NSTextView's keyDown: method I discourage it, because for most purposes it is wrong to intervene before key binding and input management. In special cases like this, it may be correct to do so. In this case, though, you may wish to consider writing a custom view instead, since it seems unlikely that you would want to use most of the features of NSTextView and NSTextField, and in fact you would probably end up trying to disable many of them (such as the caret).

Command keys are a special case--they are normally handled by the menu, rather than being passed on to the control that has keyboard focus. You may need to override NSApplication's sendEvent: method to handle them.

Douglas Davidson
_______________________________________________
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: Custom NSTextField & keyDown:
      • From: Ryan McGann <email@hidden>
References: 
 >Custom NSTextField & keyDown: (From: Ryan McGann <email@hidden>)

  • Prev by Date: Multi user
  • Next by Date: RE: Licences 101 - Copy Protection for Newbies
  • Previous by thread: Custom NSTextField & keyDown:
  • Next by thread: Re: Custom NSTextField & keyDown:
  • Index(es):
    • Date
    • Thread