简体   繁体   中英

When I get a mouseDragged event, how can I find out if it is dragging a window or just a file?

I want to respond to the drag event when it is dragging a file but not a window. I got the mouseDragged event like this:

[NSEvent addGlobalMonitorForEventsMatchingMask:NSLeftMouseDraggedMask 
                                       handler: ^(NSEvent *mouseDraggedEvent){
                                               //do something with event
                                               }];

The drag and drop system is implemented atop the event-handling system. The event-handling system (which is what you are monitoring) has no concept of what is being dragged, just that a mouse drag is occurring.

If you want to know what is being dragged then you will need to record the location of the mouse at the start of the drag and use that to calculate what is being dragged. You could use the accessibility APIs for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM