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: Vinay Prabhu <email@hidden>
- Date: Wed, 21 Jun 2006 12:43:09 +0530
- Importance: Normal
Hi,
Thanks for the help.
I have customized the NSTextField to display only numeric values from 0 -
255.
Now I want to provide the up and down arrow support, so that when I click up
arrow the
value should increment and for down arrow the value should decrement.
Since I have overridden the keyUp method, I can get it to work for one click
at a time.
If the up or down arrow key is pressed and held, the values in the text
field should continuously change.
To implement this I need to get the keyDown event. This is where I am facing
the problem.
Regards
Vinay
-----Original Message-----
From: Douglas Davidson [mailto:email@hidden]
Sent: Tuesday, June 20, 2006 9:14 PM
To: Vinay Prabhu
Cc: email@hidden
Subject: Re: Help needed with the key down event in NSTextField
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
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s)and may contain confidential or privileged information. If you are not the intended recipient, please notify the sender or email@hidden
_______________________________________________
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