mouseUp 和 mouseMove 在应用程序之外?
我正在尝试实现一种非常简单的方法来通过鼠标选择屏幕的一部分。该工作流程是许多应用程序的标准工作流程 - 单击起点,移动鼠标,然后在单击的第一个点和鼠标当前位置之间更新透明矩形。基本代码看起来像这样(减去图形,这很简单)
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" mouseDown="application1_mouseDownHandler(event)">
<fx:Script>
<![CDATA[
import spark.components.mediaClasses.VolumeBar;
private var _anchorPoint:Point = new Point();
private var _currentPoint:Point = new Point();
protected function application1_mouseDownHandler(event:MouseEvent):void
{
addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove);
addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
_anchorPoint = new Point(event.stageX, event.stageY);
}
private function handleMouseMove(e:MouseEvent):void
{
_currentPoint.x = e.stageX;
_currentPoint.y = e.stageY;
trace("rectangle between (",_anchorPoint.x, ",", _anchorPoint.y, ") and (", _currentPoint.x, ",", _currentPoint.y, ").");
}
private function handleMouseUp(e:MouseEvent):void
{
removeEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove);
removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
}
]]>
</fx:Script>
</s:Application>
当用户将鼠标移到应用程序之外时,它就会崩溃。不仅 _currentPoint 停止更新,而且如果您在应用程序外部放开鼠标按钮,您会错过 mouseUp 事件,即当您将鼠标移回到应用程序上时 _currentPoint 再次开始更新,就好像您从未放开鼠标按钮一样。想知道Flex(对于网络应用程序)是否有一种方法可以通过在应用程序外部监听 mouseMove 和 mouseUp 事件(如果可能的话)或任何其他可能有意义的方式来解决这个问题。
感谢您的帮助!
I'm trying to implement a very simple way to select a subsection of the screen via mouse. The workflow is the standard one for many apps - click on starting point, move mouse and transparent rectangle updates between first point clicked and current position of the mouse. The basic code looks something like this (minus the graphics, which is simple)
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" mouseDown="application1_mouseDownHandler(event)">
<fx:Script>
<![CDATA[
import spark.components.mediaClasses.VolumeBar;
private var _anchorPoint:Point = new Point();
private var _currentPoint:Point = new Point();
protected function application1_mouseDownHandler(event:MouseEvent):void
{
addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove);
addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
_anchorPoint = new Point(event.stageX, event.stageY);
}
private function handleMouseMove(e:MouseEvent):void
{
_currentPoint.x = e.stageX;
_currentPoint.y = e.stageY;
trace("rectangle between (",_anchorPoint.x, ",", _anchorPoint.y, ") and (", _currentPoint.x, ",", _currentPoint.y, ").");
}
private function handleMouseUp(e:MouseEvent):void
{
removeEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove);
removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
}
]]>
</fx:Script>
</s:Application>
This breaks down when the user moves the mouse outside of the app. Not only _currentPoint stops updating, but also if you let go the mouse button outside of the app you miss the mouseUp event, i.e. when you move the mouse back on the app _currentPoint starts updating again as if you had never let go of the mouse button. Was wondering if there is a way in Flex (for web apps) to get around this by listening to mouseMove and mouseUp events when outside of the app (if that's possible) or whatever other way that may make sense.
thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
大多数人不知道的是:如果 MOUSE_DOWN 事件被触发,则 MouseEvents 会在应用程序窗口之外被跟踪,但 MOUSE_UP 事件不会被触发。您可以抓取应用程序窗口之外(甚至浏览器窗口之外)的鼠标位置只要您所做的任何事情都会让用户按住鼠标。要对此进行测试,请尝试运行以下命令代码:
Here's something most people don't know: MouseEvents are tracked outside of the application window if the MOUSE_DOWN event has been fired, but not MOUSE_UP. You can grab mouse positions outside of the application window (and even outside of the browser window) as long as whatever you're doing makes the user hold their mouse down. To test this, try running the following code:
在 AIR 中进行一些黑客攻击也许可以实现这一点,但在浏览器中打开 Web 应用程序绝对不行。
想象一下,如果网站可以在浏览器之外跟踪您的鼠标并能够截取您的操作系统的屏幕截图,会发生什么!
It might be possible with some hacking in AIR, but definitely not with a webapp opened in a browser.
Just imagine what would happen if websites could track your mouse outside the browser and be able to take screenshots of your OS!
虽然这不会让您到达您想要的位置,但您可以使用
Event.MOUSE_LEAVE
和MouseEvent.MOUSE_MOVE
事件来跟踪光标是否在鼠标的边界内。应用。Though this won't get you to where you want, you can make use of
Event.MOUSE_LEAVE
andMouseEvent.MOUSE_MOVE
events to track whether the cursor is within the boundaries of the application.