Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with key-bindings for NSButtons
    primarykey
    data
    text
    <p>I have a layout with several NSButton object, and a NSTextField where the text is only selectable. The other NSButton objects have key-bindings associated, and this works perfectly until I select some text in the textfield. From there on the key bindings for the other buttons in the layout do not work anymore. </p> <p>I have looked at different solutions, like trying to set SetSelectable:NO and YES, but it seems like the text field keeps its focus and receives all the keystrokes even if it's not editable. </p> <p>I want the text in the textfield to be selectable, but if one of the other buttons is clicked, the textfield should stop receiving key-events. </p> <p>Any ideas? </p> <hr> <p>I Found a solution to this. </p> <p>At Macrumors: <a href="http://forums.macrumors.com/showthread.php?t=852807" rel="nofollow">http://forums.macrumors.com/showthread.php?t=852807</a></p> <p>I found a method, for checking if a textfield has focus: </p> <pre><code>- (BOOL)isTextFieldInFocus:(NSTextField *)textField { BOOL inFocus = NO; inFocus = ([[[textField window] firstResponder] isKindOfClass:[NSTextView class]] &amp;&amp; [[textField window] fieldEditor:NO forObject:nil]!=nil &amp;&amp; [textField isEqualTo:(id)[(NSTextView *)[[textField window] firstResponder]delegate]]); return inFocus; } </code></pre> <p>Then in the Update method that is executed on all the NSButtons, I wrote: </p> <pre><code>if ([self isTextFieldInFocus:display]) { [display setHidden:YES]; [display setHidden:NO]; } </code></pre> <p>where display, is the name of the NSTextField outlet. </p> <p>Now, when I select some text, and then press one of the buttons, the key-bindings on the NSButtons are back in place working. This allows the user to select and copy text, but then he has to push one button to enter keystrokes, and this I think is OK. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload