Getting mouseMoved / mouseDragged outside my NSView window

I am currently porting an application (or rather, a VST plugin) from windows to OSX. I am new to OSX programming, but I am using Cocoa NSView added to the Carbon window (which I get from the host) using HICocoaCreateView.

Anywhoo ... Inside this view, I want to receive mouseMoved and mouseDragged events, but when dragging I also want to get these events even when the mouse leaves my NSView (as well as the parent window), but I just can't seem to do it.

In windows, I would do SetCapture on mouseDown to get all mouse events for a while. The closest thing I found in Cocoa is "addGlobalMonitorForEventsMatchingMask", but it is only 10.6+, and I hardly believe that it was impossible to do before. (After all, this is what is commonly used for draggable components such as scrollbars, etc.).

It drives me crazy!

UPDATE:

There's something called CGEventTapCreate, which, as far as I can tell from rare documents, looks like addGlobalMonitor ... but in Carbon. I did not understand how Carbon and Cocoa relate to each other and what works there. Is this possible, although my main material is Cocoa? (The window I get from the host can be either Cocoa or Carbon. It's really a mess.)

+3
source
2

CGEventTap Carbon. Quartz, Cocoa ( ). Carbon - ( ) , Mac OS 9, C Mac OS X, Objective-C. C, Apple, - Carbon; Quartz Grand Central Dispatch spring , C ( , ).

, Cocoa. , addGlobalEventMonitor... addLocalEventMonitor... - Obj-C CGEventTap s.

, CGEventTap - . , , . Dave DeLong SO .

+3

, - ...

EventHandlerRef     m_ApplicationMouseDragEventHandlerRef;          
EventHandlerRef     m_MonitorMouseDragEventHandlerRef;

{
    OSStatus ErrStatus;

    static const EventTypeSpec kMouseDragEvents[] =
      {
        { kEventClassMouse, kEventMouseDragged }
      };

    ErrStatus = InstallEventHandler(GetEventMonitorTarget(), NewEventHandlerUPP(MouseHasDragged), GetEventTypeCount(kMouseDragEvents), kMouseDragEvents, this, &m_MonitorMouseDragEventHandlerRef);

    ErrStatus = InstallApplicationEventHandler(NewEventHandlerUPP(MouseHasDragged), GetEventTypeCount(kMouseDragEvents), kMouseDragEvents, this, &m_ApplicationMouseDragEventHandlerRef);

    return true;
}

//implement these functions
OSStatus MouseHasDragged(EventHandlerCallRef inCaller, EventRef inEvent, void *pUserData){}

EventTypeSpec / , . . .

!

+2

All Articles