0

I want to assign a key equivalent to an NSButton if the control is the first responder.

Abizern
  • 146,289
  • 39
  • 203
  • 257
Javier Beltrán
  • 756
  • 5
  • 26
  • A key? Like a unique identifier? – Black Frog May 30 '11 at 17:09
  • possible duplicate of [NSButton key equivalent](http://stackoverflow.com/questions/5025810/nsbutton-key-equivalent) – jscs May 30 '11 at 18:35
  • @Black Frog: A "key equivalent" is a keyboard shortcut assigned to trigger the action of a control (like a menu item or button). – Joshua Nozzi May 30 '11 at 18:40
  • @Josh Caswell: I don't think this is quite the same question. At least the accepted answer to the proposed dupe isn't exactly right for any given equivalent (it only deals with return key as equiv for default window cell). – Joshua Nozzi May 30 '11 at 18:45

1 Answers1

1

You can override becomeFirstResponder: and in your implementation call setKeyEquivalent:. If you want to remove the key equivalent when the button loses first responder status, override resignFirstResponder:.

SSteve
  • 10,550
  • 5
  • 46
  • 72
  • 1
    @Javier: You do this in the control whose first-responder status you want to affect the button's equivalent. For example, if you have a view as a container and it can become first responder, you'd override -becomeFirstResponder: (calling super) then manage the button's equivalent there. If you don't yet understand these topics, you have a lot of prerequisite reading to do because a simple answer isn't possible here. – Joshua Nozzi May 30 '11 at 18:42