Capture "Space" key event

  • I am writing an app where I would like to capture the space key event,
    much as iTunes does.

    My guess was to sub class NSApplication, but of course events don't get
    passed down the chain.

    Is there any way to capture this event short of subclassing every
    window?

    Thanks for your help,

    Mat
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On 5. Mar 2004, at 14:53, Mathew Peterson wrote:

    > My guess was to sub class NSApplication, but of course events don't
    > get passed down the chain.

    From the NSApplication documentation, so I would think your guess is
    correct:

    - (void)sendEvent:(NSEvent *)anEvent

    Dispatches anEvent to other objects. You rarely invoke sendEvent:
    directly, although you might want to override this method to perform
    some action on every event. sendEvent: messages are sent from the main
    event loop (the run method). sendEvent: is the method that dispatches
    events to the appropriate respondersNSApp handles application events,
    the NSWindow indicated in the event record handles window-related
    events, and mouse and key events are forwarded to the appropriate
    NSWindow for further dispatching.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Allan,

    In my Program I tried making my window it a subclass of NSWindow
    And using that keyDown:(NSEvent*)anEvent
    to get the delete key so I can delete a row from my NSTableView,
    but it is not working,  in fact the keyDown is not getting any events
    at all.
    Is there something I am missing?

    MAtt

    On Mar 5, 2004, at 8:05 AM, Allan Odgaard wrote:

    > On 5. Mar 2004, at 14:53, Mathew Peterson wrote:
    >
    >> My guess was to sub class NSApplication, but of course events don't
    >> get passed down the chain.
    >
    > From the NSApplication documentation, so I would think your guess is
    > correct:
    >
    > - (void)sendEvent:(NSEvent *)anEvent
    >
    > Dispatches anEvent to other objects. You rarely invoke sendEvent:
    > directly, although you might want to override this method to perform
    > some action on every event. sendEvent: messages are sent from the main
    > event loop (the run method). sendEvent: is the method that dispatches
    > events to the appropriate respondersNSApp handles application events,
    > the NSWindow indicated in the event record handles window-related
    > events, and mouse and key events are forwarded to the appropriate
    > NSWindow for further dispatching.
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On 5. Mar 2004, at 16:20, Matt Jaffa wrote:

    > In my Program I tried making my window it a subclass of NSWindow
    > And using that keyDown:(NSEvent*)anEvent
    > to get the delete key so I can delete a row from my NSTableView,
    > but it is not working,  in fact the keyDown is not getting any events
    > at all.
    > Is there something I am missing?

    As I understand it, NSApp will get the event from the main event loop,
    it will pass it on to the window which has stat as key using
    sendEvent:, the window will send the event to the first responder using
    keyDown: or whatever matches the event -- if the first responder does
    not implement this method, the default implementation will pass it on
    to the next object in the responder chain a.s.o.

    So only if no-one implements keyDown: in the responder chain will your
    window receive a keyDown: (or if those who do implement it, decides to
    pass on the message to the next responder).

    So you should probably overwrite sendEvent: instead of keyDown:, if you
    insist on placing this in your window subclass (it ought to be in the
    table view subclass).
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Allan,

    I looked at the online documentation,
    There is no keyDown  or sendEvent  Method in the NSTableView.
    So How can I overide by subclassing the NSTableView, when it does not
    exist?

    Matt

    On Mar 5, 2004, at 8:33 AM, Allan Odgaard wrote:

    > On 5. Mar 2004, at 16:20, Matt Jaffa wrote:
    >
    >> In my Program I tried making my window it a subclass of NSWindow
    >> And using that keyDown:(NSEvent*)anEvent
    >> to get the delete key so I can delete a row from my NSTableView,
    >> but it is not working,  in fact the keyDown is not getting any events
    >> at all.
    >> Is there something I am missing?
    >
    > As I understand it, NSApp will get the event from the main event loop,
    > it will pass it on to the window which has stat as key using
    > sendEvent:, the window will send the event to the first responder
    > using keyDown: or whatever matches the event -- if the first responder
    > does not implement this method, the default implementation will pass
    > it on to the next object in the responder chain a.s.o.
    >
    > So only if no-one implements keyDown: in the responder chain will your
    > window receive a keyDown: (or if those who do implement it, decides to
    > pass on the message to the next responder).
    >
    > So you should probably overwrite sendEvent: instead of keyDown:, if
    > you insist on placing this in your window subclass (it ought to be in
    > the table view subclass).
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On 5. Mar 2004, at 16:41, Matt Jaffa wrote:

    > I looked at the online documentation,
    > There is no keyDown  or sendEvent  Method in the NSTableView.
    > So How can I overide by subclassing the NSTableView, when it does not
    > exist?

    NSTableView inherits from NSResponder. NSResponder implements keyDown:.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On Mar 5, 2004, at 7:41 AM, Matt Jaffa wrote:

    > Allan,
    >
    > I looked at the online documentation,
    > There is no keyDown  or sendEvent  Method in the NSTableView.
    > So How can I overide by subclassing the NSTableView, when it does not
    > exist?
    >
    > Matt

    Consider what NSTableView is a subclass of [1]... look up the chain at
    those classes documentation, in this case NSResponder [2].

    It is best to get an understanding of the overall design of AppKit to
    work best in it. The following page helps to give an overview...

    <http://developer.apple.com/documentation/Cocoa/Reference/
    ApplicationKit/ObjC_classic/Intro/IntroAppKit.html
    >

    ...and in this case...

    <http://developer.apple.com/documentation/Cocoa/Conceptual/
    BasicEventHandling/index.html
    >

    -Shawn

    [1] Inherits from: NSText : NSView : NSResponder : NSObject
    [2]
    <http://developer.apple.com/documentation/Cocoa/Reference/
    ApplicationKit/ObjC_classic/Classes/NSResponder.html
    >
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • At 8:41 AM -0700 3/5/04, Matt Jaffa wrote:
    > Allan,
    >
    > I looked at the online documentation,
    > There is no keyDown  or sendEvent  Method in the NSTableView.
    > So How can I overide by subclassing the NSTableView, when it does not exist?
    >
    > Matt

    NSTableView is a sublcass of NSResponder, which has keyDown - I
    recommend installing ApKiDo which makes it trivial to see things like
    this (since it can show either the methods of just the class, or all
    inherited methods).

    --
    Glenn Andreas                      <gandreas...>
    Theldrow, Blobbo, Cythera, oh my!
    Be good, and you will be lonesome
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Thanks
    Allan, Shawn, and anyone else I didn't mention.
    Hmm it does in the online documentation say it is subclassed my
    NSFirstResponder.
    My mistake,

    thanks a bunch,
    Matt

    On Mar 5, 2004, at 9:06 AM, Shawn Erickson wrote:

    > On Mar 5, 2004, at 7:41 AM, Matt Jaffa wrote:
    >
    >> Allan,
    >>
    >> I looked at the online documentation,
    >> There is no keyDown  or sendEvent  Method in the NSTableView.
    >> So How can I overide by subclassing the NSTableView, when it does not
    >> exist?
    >>
    >> Matt
    >
    > Consider what NSTableView is a subclass of [1]... look up the chain at
    > those classes documentation, in this case NSResponder [2].
    >
    > It is best to get an understanding of the overall design of AppKit to
    > work best in it. The following page helps to give an overview...
    >
    > <http://developer.apple.com/documentation/Cocoa/Reference/
    > ApplicationKit/ObjC_classic/Intro/IntroAppKit.html>
    > BasicEventHandling/index.html>
    >
    > -Shawn
    >
    > [1] Inherits from: NSText : NSView : NSResponder : NSObject
    > [2]
    > <http://developer.apple.com/documentation/Cocoa/Reference/
    > ApplicationKit/ObjC_classic/Classes/NSResponder.html>
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month march 2004 next month
MTWTFSS
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        
Go to today