Re: Intercepting keyDown event from NSComboBox
Re: Intercepting keyDown event from NSComboBox
- Subject: Re: Intercepting keyDown event from NSComboBox
- From: Graham <email@hidden>
- Date: Wed, 13 Feb 2008 13:13:37 +1100
On 13/02/2008, at 12:07 PM, Randall Meadows wrote:
I have a window that has an NSComboBox in it; it is the only thing
in the window that can acquire keyboard focus.
The window also has a button in it, which my client has decided he
wants activated by pressing the space bar. Therefore I need a way
to intercept keyDown events to the combo box (which *always* has
keyboard focus).
My first attempt was to subclass the NSComboBox, and receive the
controlTextDidChange notification, look for a space character in
the stringValue of the control (any other valid value of the combo
box will NOT contain a space character), and if one is found,
delete it and call performClick on the button. This works, but I
view it as an ugly hack. And, it has a nasty side effect: if any
of the text displayed in the combo box is selected, that selection
effectively gets deleted; this is counter to the purpose of the
combo box, which is to display information about the current
"stuff" being worked on in the window. I'm thinking I can get
around this by refreshing the display of the combo box with the
current value, but to me that's just adding more ugly to the
hackery that I dislike to begin with.
Is there a better way to intercept keyDown events before the
firstResponder gets a whack at it? (Assume that changing the
actual UI/UE, at this point, is not an option.)
Or re-educate the client ;-) What if he wants to type a space into
the combo-box?
While this is an unhelpful and glib answer, I do feel we have to at
least try to get clients to understand why things are not done
certain ways and why deeper thinking on an issue will often make them
realise that any given idea can be worse than useless.
--------
S.O.S.
_______________________________________________
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