java 获取鼠标选中内容,如何在java中获取鼠标中键?

本文介绍了如何使用`Event.ALT_MASK`标志来检测鼠标事件中的中键按下,以及为何推荐替换过时的mouseDown方法,转而使用processMouseEvent。讨论了mouseDown的局限性和新技术的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

How can i differentiate the left from the middle button?

Or if it is impossible with mouseDown, what should i use?

解决方案

Try using 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.

So your code might be:

if (ev.modifiers & Event.ALT_MASK != 0) {

// middle button was pressed

}

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值