Re: Help needed with the key down event in NSTextField
Re: Help needed with the key down event in NSTextField
- Subject: Re: Help needed with the key down event in NSTextField
- From: Douglas Davidson <email@hidden>
- Date: Tue, 20 Jun 2006 08:43:54 -0700
On Jun 20, 2006, at 5:45 AM, Vinay Prabhu wrote:
I am using NSTextFiled in my application.
I have subclassed the NSTextField and implemented the
"keyDown" and "keyUp" methods.
The problem is, when any key pressed, only the "keyUp" is called
"keyDown"
is not called.
Any idea, when "keyDown" is called?
First, NSTextField and similar controls generally do not deal with
editing. When a control is editing, a field editor (an NSTextView)
is used. Read the documentation on field editors.
Second, you probably do not want to deal with key events at the
keyDown: and keyUp: level. Here is my usual introduction to key
event processing:
Here is the normal sequence when a text view receives key events:
NSTextView's keyDown: 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).
In particular, non-text keys like enter or return will (with the
standard key bindings) end up using doCommandBySelector: to call
methods like insertNewline: on the NSTextView.
If you are using an NSTextView, you should be able to implement the
text view delegate method
- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)
aSelector;
and examine the selector. If you are using an NSTextField or
similar control, you can implement their delegate method
- (BOOL)control:(NSControl *)control textView:(NSTextView *)
textView doCommandBySelector:(SEL)aSelector;
If you're interested in normal text keys, then the best option
would be to use an NSFormatter. That allows you to validate
partial and/or complete strings.
If you want to do something other than what NSFormatter does, you
can use text-did-change notifications and the like, but the details
depend on exactly what you want to do.
Douglas Davidson
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden