简体   繁体   English

当我获得mouseDragged事件时,如何确定它是拖动窗口还是只是文件?

[英]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: 我得到了mouseDragged事件,如下所示:

[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. 您可以为此使用可访问性API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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