Java 通过 ctrl click 检测在 OSX 上释放了哪个 mouseButton
Posted
技术标签:
【中文标题】Java 通过 ctrl click 检测在 OSX 上释放了哪个 mouseButton【英文标题】:Java detect which mouseButton is released on OSX with ctrl click 【发布时间】:2019-03-12 09:16:39 【问题描述】:我尝试跟踪BUTTON1
BUTTON2
和BUTTON3
是否被按下。
问题是在 OSX 上 ctrl + click
被视为右键单击。
所以如果我有以下(使用处理):
boolean mouse_left_pressed;
boolean mouse_right_pressed;
void setup()
size(200, 100);
void draw()
background(0);
fill(255);
text("left: "+mouse_left_pressed, 50, 50);
text("right: "+mouse_right_pressed, 50, 75);
public void mousePressed(MouseEvent e)
if (e.getButton() == LEFT) mouse_left_pressed = true;
if (e.getButton() == RIGHT) mouse_right_pressed = true;
public void mouseReleased(MouseEvent e)
if (e.getButton() == LEFT) mouse_left_pressed = false;
if (e.getButton() == RIGHT) mouse_right_pressed = false;
如果我执行以下步骤:
用鼠标左键单击并按住 按住控制键 松开鼠标左键然后虽然我没有再按下鼠标,但mouse_left_pressed
的状态仍然是真实的。
有没有办法获得实际释放的鼠标按钮?
【问题讨论】:
【参考方案1】:这是因为在 OSX 中 control+left-click 等同于 right-click。它有点 hack,但您可以按如下方式检查修饰符:
boolean mouse_left_pressed;
boolean mouse_right_pressed;
void setup()
size(200, 100);
void draw()
background(0);
fill(255);
text("left: "+mouse_left_pressed, 50, 50);
text("right: "+mouse_right_pressed, 50, 75);
public void mousePressed(MouseEvent e)
if (e.getButton() == LEFT) mouse_left_pressed = true;
if (e.getButton() == RIGHT)
if (!e.isControlDown())
mouse_right_pressed = true;
else
mouse_left_pressed = true;
public void mouseReleased(MouseEvent e)
println(e);
if (e.getButton() == LEFT) mouse_left_pressed = false;
if (e.getButton() == RIGHT)
if (!e.isControlDown())
mouse_right_pressed = false;
else
mouse_left_pressed = false;
【讨论】:
以上是关于Java 通过 ctrl click 检测在 OSX 上释放了哪个 mouseButton的主要内容,如果未能解决你的问题,请参考以下文章
检测到 LoaderLock:DLL"XXXX"正试图在OS加载程序锁内执行
如何使用ctrl +单击阻止javascript阻止打开新选项卡