gpt4 book ai didi

java - BUTTON1_MASK 和 BUTTON1_DOWN_MASK 有什么区别?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:40:19 27 4
gpt4 key购买 nike

来自java网站:

BUTTON1_DOWN_MASK = The Mouse Button1 extended modifier constant.
BUTTON1_MASK = The Mouse Button1 modifier constant.

我什至不确定“修饰常数”是什么。更不用说扩展了。不过,我确实理解 BUTTON1_MASK 只是单击鼠标左键时的整数表示。

最佳答案

BUTTON1_MASK 是指示事件来自按钮 1 的掩码。BUTTON1_DOWN_MASK 在概念上类似,但是是该常量的扩展 版本。

有两种方法可以返回此类常量集:InputEvent#getModifiers()InputEvent#getModifiersEx(),它们将返回修饰符常量,或 分别扩展修饰符常量。

From the docs (bold is mine) :

The button mask returned by InputEvent.getModifiers() reflects only the button that changed state, not the current state of all buttons ... To get the state of all buttons and modifier keys, use InputEvent.getModifiersEx().

and also (bold is mine) :

Extended modifiers represent the state of all modal keys, such as ALT, CTRL, META, and the mouse buttons just after the event occurred

For example, if the user presses button 1 followed by button 2, and then releases them in the same order, the following sequence of events is generated:

MOUSE_PRESSED:  BUTTON1_DOWN_MASK
MOUSE_PRESSED: BUTTON1_DOWN_MASK | BUTTON2_DOWN_MASK
MOUSE_RELEASED: BUTTON2_DOWN_MASK
MOUSE_CLICKED: BUTTON2_DOWN_MASK
MOUSE_RELEASED:
MOUSE_CLICKED:

如果您只想检测按钮 1(通常是左键)单击,那么这些中的任何一个都应该起作用:

if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
System.out.println("BUTTON1_MASK");
}

if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
System.out.println("BUTTON1_DOWN_MASK");
}

此外,您还可以查看这个开源版本的InputEventwhich has some more useful comments, and shows what's happening inside

关于java - BUTTON1_MASK 和 BUTTON1_DOWN_MASK 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16410228/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com