有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何在java中获取鼠标中键?

我使用public boolean mouseDown(Event ev, int x, int y)来检测鼠标的点击
我可以区分鼠标右键(ev.metaDown()为true)和左键和中键

如何区分左键和中键? 或者如果mouseDown不可能,我应该使用什么


共 (3) 个答案

  1. # 1 楼答案

    尝试使用ALT_MASK

    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

  2. # 3 楼答案

    mouseDown已被弃用。你所需要的一切都可以通过MouseEvent访问getButton。轨道按钮3