如何检测鼠标左键按下时的移动?
我想在按下左键时检测鼠标移动。
我只是创建一个绘图应用程序。我可以在不按下任何鼠标的情况下检测鼠标移动。但我想用鼠标左键检测它。
我认为没有人愿意听这个。那么,这样做的想法是什么?
I would like to detect mouse movement while the left button is pressed.
I'm simply creating a drawing application. I can detect mouse movement without any mouse being pressed. But I want to detect it WITH left mouse pressed.
I don't think there's a listener for this. So, what is the idea to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
MouseMotionListener 中有 mouseDragged 方法...检查这个更多细节...
there is mouseDragged method in MouseMotionListener...check this out for more details...
在 MouseMotionListener 中,您可以使用以下命令检查这一点:
并且您将侦听 mouseDragged 事件。
In your MouseMotionListener you can check for this using:
and you would listen for the mouseDragged event.
我认为可能有某种鼠标拖动侦听器,但如果没有......
捕获鼠标按钮按下和向上事件。在这些事件中,设置一个布尔值,例如
leftButtonIsDown = true
(除非已经有一些简单的方法来查询它),然后在鼠标移动事件中使用像if (leftButtonIsDown)
这样的块代码>I think there might be some sort of mouse drag listener, but if not...
Capture the mouse button down and up events. In those events, set a boolean such as
leftButtonIsDown = true
(unless there's already some easy way to query that) and then in the mouse movement events use a block likeif (leftButtonIsDown)