Intercepting keyDown event from NSComboBox
Intercepting keyDown event from NSComboBox
- Subject: Intercepting keyDown event from NSComboBox
- From: Randall Meadows <email@hidden>
- Date: Tue, 12 Feb 2008 18:07:24 -0700
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.)
Thanks!
randy
_______________________________________________
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