Receiving mouseEnter and mouseExit events.

  • I'm a little confused on the mouse tracking. I have a view and I want
    to track when the mouse enters and exits it. If I set
    setAcceptsMouseMovedEvents to true for my window, (void)mouseMoved:
    (NSEvent *)theEvent will get called. But, - (void)mouseEntered:
    (NSEvent *)theEvent and - (void)mouseExited:(NSEvent *)theEvent will
    not. Am I correct in my understanding that I need to create a
    NSTrackingArea for these events to get called?

    thanks for the help
    Dave
  • On Aug 19, 2008, at 12:04, David Alter wrote:

    > I'm a little confused on the mouse tracking. I have a view and I
    > want to track when the mouse enters and exits it. If I set
    > setAcceptsMouseMovedEvents to true for my window, (void)mouseMoved:
    > (NSEvent *)theEvent will get called. But, - (void)mouseEntered:
    > (NSEvent *)theEvent and - (void)mouseExited:(NSEvent *)theEvent will
    > not. Am I correct in my understanding that I need to create a
    > NSTrackingArea for these events to get called?

    Yes, create a tracking area, but *don't* setAcceptsMouseMovedEvents:YES.

    Both mechanisms result in mouseMoved events, but you only want the
    events produced by the tracking area. (Well, you may not want
    mouseMoved events at all, just mouseEntered and mouseExited, but you
    tell the tracking area which of its possible events you want.)
  • I just realized that NSTrackingArea is 10.5 and up. I need to support
    10.4. mouseEntered and mouseExited have been part of NSResponder from
    10.0. To receive these events in 10.4 what should I do?

    thanks
    -dave

    On Aug 19, 2008, at 12:55 PM, Quincey Morris wrote:

    > On Aug 19, 2008, at 12:04, David Alter wrote:
    >
    >> I'm a little confused on the mouse tracking. I have a view and I
    >> want to track when the mouse enters and exits it. If I set
    >> setAcceptsMouseMovedEvents to true for my window, (void)mouseMoved:
    >> (NSEvent *)theEvent will get called. But, - (void)mouseEntered:
    >> (NSEvent *)theEvent and - (void)mouseExited:(NSEvent *)theEvent
    >> will not. Am I correct in my understanding that I need to create a
    >> NSTrackingArea for these events to get called?
    >
    > Yes, create a tracking area, but *don't*
    > setAcceptsMouseMovedEvents:YES.
    >
    > Both mechanisms result in mouseMoved events, but you only want the
    > events produced by the tracking area. (Well, you may not want
    > mouseMoved events at all, just mouseEntered and mouseExited, but you
    > tell the tracking area which of its possible events you want.)
    >

    www.AlterConsulting.net
    510-868-0916 Office
    510-435-4391 Mobile
  • Figured it out. I just need to use

    addTrackingRect:owner:userData:assumeInside

    enjoy
    -dave

    On Aug 19, 2008, at 2:50 PM, David Alter wrote:

    > I just realized that NSTrackingArea is 10.5 and up. I need to
    > support 10.4. mouseEntered and mouseExited have been part of
    > NSResponder from 10.0. To receive these events in 10.4 what should I
    > do?
    >
    > thanks
    > -dave
    >
    > On Aug 19, 2008, at 12:55 PM, Quincey Morris wrote:
    >
    >> On Aug 19, 2008, at 12:04, David Alter wrote:
    >>
    >>> I'm a little confused on the mouse tracking. I have a view and I
    >>> want to track when the mouse enters and exits it. If I set
    >>> setAcceptsMouseMovedEvents to true for my window, (void)mouseMoved:
    >>> (NSEvent *)theEvent will get called. But, - (void)mouseEntered:
    >>> (NSEvent *)theEvent and - (void)mouseExited:(NSEvent *)theEvent
    >>> will not. Am I correct in my understanding that I need to create a
    >>> NSTrackingArea for these events to get called?
    >>
    >> Yes, create a tracking area, but *don't*
    >> setAcceptsMouseMovedEvents:YES.
    >>
    >> Both mechanisms result in mouseMoved events, but you only want the
    >> events produced by the tracking area. (Well, you may not want
    >> mouseMoved events at all, just mouseEntered and mouseExited, but
    >> you tell the tracking area which of its possible events you want.)
    >>
    >
    > www.AlterConsulting.net
    > 510-868-0916 Office
    > 510-435-4391 Mobile
    >

    www.AlterConsulting.net
    510-868-0916 Office
    510-435-4391 Mobile
  • On Tue, Aug 19, 2008 at 23:50, David Alter <david...> wrote:
    > I just realized that NSTrackingArea is 10.5 and up. I need to support 10.4.
    > mouseEntered and mouseExited have been part of NSResponder from 10.0. To
    > receive these events in 10.4 what should I do?

    Sorry for the very late reply, but you might still be interested in
    MATrackingArea, which can be found at http://mattgemmell.com/source.
    It's almost identical in functionality to NSTrackingArea, and supports
    10.4+ (which seems to be just be what you need).

    Regards
    Mattias
previous month august 2008 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