如何在java中获取鼠标中键? [英] How to fetch the middle mouse button in java?

查看:202
本文介绍了如何在java中获取鼠标中键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 public boolean mouseDown(Event ev,int x,int y)来检测鼠标的点击。

我可以区分鼠标右键(ev.metaDown()为true)和左侧和中部。

I use public boolean mouseDown(Event ev, int x, int y) to detect a click of the mouse.
I can distinguish between the right mouse button (ev.metaDown() is true) and the left and middle.

我如何区分左侧的中间按钮?
或者如果mouseDown不可能,应该使用什么?

How can i differentiate the left from the middle button? Or if it is impossible with mouseDown, what should i use?

推荐答案

尝试使用 ALT_MASK


此标志表示事件发生时Alt键已关闭。对于鼠标事件,该标志表示鼠标中键被按下或释放。

This flag indicates that the Alt key was down when the event occurred. For mouse events, this flag indicates that the middle mouse button was pressed or released.

所以你的代码可能是:

if (ev.modifiers & Event.ALT_MASK != 0) {
    // middle button was pressed
}

当然,这一切假设你有一个很好的理由首先使用mouseDown,因为它已被弃用。你应该(可能)使用 processMouseEvent ,这样可以让您使用MouseEvent来玩。

Of course, all this is assuming you have a very good reason to use mouseDown in the first place, since it is deprecated. You should (probably) be using processMouseEvent instead, which gives you a MouseEvent to play with.

这篇关于如何在java中获取鼠标中键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆