如何检测Mac OS的右键单击事件 [英] How to detect right-click event for Mac OS
问题描述
对于Windows和Linux,我能够检测到右键单击。但对于mac我不知道如何检测右键单击。
For windows and linux I am able to detect right click. But for mac I donot know how to detect right-click.
如何编写java程序以检测Mac OS的右键单击
How to write java program to detect right click for Mac OS
谢谢
Sunil KUmar Sahoo
Thanks Sunil KUmar Sahoo
推荐答案
这与检测右键单击Windows或Linux-您调用给定的MouseEvent的 getButton()
方法来检查是否单击了 BUTTON3
。例如,看一下示例MouseListener的以下片段:
It's the same as detecting a right-click on Windows or Linux—you call your given MouseEvent's getButton()
method to check if BUTTON3
was clicked. For example, take a look at the following snippet of an example MouseListener:
public class MyListener implements MouseListener
{
// ... code ...
public void mouseClicked(MouseEvent event)
{
if (event.getButton() == MouseButton.BUTTON3)
{
// Right-click happened
}
}
}
但是,如果用户实际上有一个双键鼠标,则只检测右键单击。由于大多数Mac鼠标在不久之前只有一个按钮,因此您可能还需要考虑检测控制点击(这是当时右键单击的常用习惯用法)。如果您决定这样做,那么实现非常简单:只需添加另一个检查,如果 event.isControlDown()
返回true。
However, this only detects right-clicks if the user actually has a two-button mouse. Since most Mac mice had only one button as of not-too-long-ago, you might want to consider detecting Control-clicks as well (which was the common idiom for right-clicking back then). If you decide to do so, the implementation is pretty trivial: just add another check for if event.isControlDown()
returns true.
这篇关于如何检测Mac OS的右键单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!