keyDown: in NSMatrix subclass

Ask a Question related to Mac Programming, Design and Development.

  1. #1

    Default Re: keyDown: in NSMatrix subclass

    In <znu-55B7B3.11560309072003@news.fu-berlin.de> ZnU wrote:
    > I'm trying to override keyDown: in an NSMatrix subclass so I can
    > implement some reasonable behavior for arrow keys, but I never seem to
    > receive any key events. The documentation isn't being particularly
    > helpful. What's going on here? Are my events being eaten by the
    > containing NSScrollView? If so, is there a way to get it to cut that
    > out without subclassing it?
    I presume you remembered to dick around with acceptsFirstResponder? When
    that doesn't work, what I do is override NSWindow's sendEvent:. I test
    for an NSKeyDown event and then ask the window's delegate what to do.
    The window's delegate can look to see who is firstResponder and
    implement special behavior if desired, or just report that we should
    keep our hands off, in which case we call the super's functionality.
    Perhaps this is overkill but it works great for me; I've used it to mend
    many apparent incoherencies in Cocoa's key handling. m.

    --
    matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt[/url]
    REALbasic: The Definitive Guide! 2nd edition!
    [url]http://www.amazon.com/exec/obidos/ASIN/0596001770/somethingsbymatt[/url]
    Subscribe to TidBITS. It's free and smart.
    matt neuburg Guest

  2. Similar Questions and Discussions

    1. keyDown
      hie again, i have 3 textbox and i would like the user to go to the next textbox by pressing the 'ENTER' key. i have tried using this: Private...
    2. Cocoa: NSMatrix, change number of cells, can't target new ones
      I have an NSMatrix of buttons. They work fine and the target is called when I click on one of them. I've set it up as just -...
    3. Cocoa: detecting click in NSMatrix
      Okay, how the hell am I meant to do this ? I've set an IBAction as the target for my matrix and my routine does actually get called when the user...
    4. setToolTip and NSMatrix of NSButton
      What is wrong with this code: matrix_of_but is a NSMatrix of NSButton NSButton *but; but = ; ; CW report this error (for the last line)
    5. keyDown & keyUp?????
      Can anyone tell me why the keyDown and keyUp handlers don't work when SW3D is inserted in a movie. chartonum(the keypressed) works, but that...
  3. #2

    Default Re: keyDown: in NSMatrix subclass

    In <znu-27DE66.09010313072003@news.fu-berlin.de> ZnU wrote:
    > I stuck:
    >
    > [[self window] makeFirstResponder:self];
    >
    > in acceptsFirstResponder. This seems to work.
    That seems really dangerous to me. Are you quite sure that you couldn't
    get the desired result by returning YES from both acceptFirstResponder
    and becomeFirstResponder, which is the canonical way to do it? m.


    --
    matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt[/url]
    REALbasic: The Definitive Guide! 2nd edition!
    [url]http://www.amazon.com/exec/obidos/ASIN/0596001770/somethingsbymatt[/url]
    Subscribe to TidBITS. It's free and smart.
    matt neuburg Guest

  4. #3

    Default Re: keyDown: in NSMatrix subclass

    In article <20030713091723225-0700@news.la.sbcglobal.net>,
    matt neuburg <matt@tidbits.com> wrote:
    > In <znu-27DE66.09010313072003@news.fu-berlin.de> ZnU wrote:
    > > I stuck:
    > >
    > > [[self window] makeFirstResponder:self];
    > >
    > > in acceptsFirstResponder. This seems to work.
    >
    > That seems really dangerous to me. Are you quite sure that you couldn't
    > get the desired result by returning YES from both acceptFirstResponder
    > and becomeFirstResponder, which is the canonical way to do it? m.
    Positive. If I simply do that, becomeFirstResponder never even gets
    called.

    --
    "First, let me make it very clear, poor people aren't necessarily killers. Just
    because you happen to be not rich doesn't mean you're willing to kill."
    -- George W. Bush in Washington, D.C. on May 19, 2003
    ZnU Guest

  5. #4

    Default Re: keyDown: in NSMatrix subclass

    In article <20030715082836994-0700@news.la.sbcglobal.net>,
    matt neuburg <matt@tidbits.com> wrote:
    > In <znu-E93F54.10495515072003@news.fu-berlin.de> ZnU wrote:
    > > In article <20030713091723225-0700@news.la.sbcglobal.net>,
    > > matt neuburg <matt@tidbits.com> wrote:
    > >
    > >> In <znu-27DE66.09010313072003@news.fu-berlin.de> ZnU wrote:
    > >> > I stuck:
    > >> >
    > >> > [[self window] makeFirstResponder:self];
    > >> >
    > >> > in acceptsFirstResponder. This seems to work.
    > >>
    > >> That seems really dangerous to me. Are you quite sure that you
    > >> couldn't get the desired result by returning YES from both
    > >> acceptFirstResponder and becomeFirstResponder, which is the
    > >> canonical way to do it? m.
    > >
    > > Positive. If I simply do that, becomeFirstResponder never even gets
    > > called.
    >
    > But that's only because you're not doing anything to cause the NSMatrix
    > subclass to be the first responder in the first place! It doesn't happen
    > all by itself, you know.
    >
    > In other words, what I'm saying is, don't call makeFirstResponder inside
    > acceptsFirstResponder - that's a sort of circular corruption of the
    > framework - but do call it! In your window controller's awakeFromNib,
    > for example, say something like this:
    >
    > [[myMatrix window] makeFirstResponder: myMatrix];
    That works initially, of course. But if another view becomes the first
    responder, there's no way to make the matrix the first responder again;
    when it's clicked, acceptsFirstResponder gets called and then... nothing.
    I suppose I could send the makeFirstResponder message from mouseDown
    rather than from acceptsFirstResponder, but that seems functionally
    identical in this case; there appears to be a one-to-one correspondence
    between clicks on the view and calls to acceptsFirstResponder.

    [snip]

    --
    "First, let me make it very clear, poor people aren't necessarily killers. Just
    because you happen to be not rich doesn't mean you're willing to kill."
    -- George W. Bush in Washington, D.C. on May 19, 2003
    ZnU Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139