如何区分触摸板点击

How to differentiate between touchpad clicks

我正在 Java 中为鼠标垫创建点击测试。我可以区分左,右,中点击:

if(evt.getButton()==3) // or 1 or 2

我似乎无法区分 2 个左边。

左边的2个在上图中点击1再点击2。我试图通过调试和检查事件对象来查看当我单击时是否从它们那里获得了不同的值,但它是相同的。对于键盘,可以通过获取 keyLocation 来区分两个 Ctrl 或 2 个 shifts,是否可以通过单击来做类似的事情?就像不知道点击了屏幕上的什么地方,而是按下了哪个按钮。

private void formMouseClicked(java.awt.event.MouseEvent evt) {
    System.out.println(evt.getButton());
    if (evt.getButton() == 3) {
        //3=right
        button1.setBackground(Color.GREEN);
        textField1.setText("Code : Right");
    } else if (evt.getButton() == 2) {
        //middle
        button6.setBackground(Color.GREEN);
        textField1.setText("Code : Middle");
    } else if (evt.getButton() == 1) {
        //1=left
        button5.setBackground(Color.GREEN);
        textField1.setText("Code : Left");
    } else {
        textField1.setText("Code : " + evt.getButton());
    }
}

以上是我目前为止关于点击的代码。

我已经搜索了很多,但找不到有用的信息。

你可以在下面的代码 SwingUtilities methods

SwingUtilities.isLeftMouseButton(MouseEvent anEvent) 
SwingUtilities.isRightMouseButton(MouseEvent anEvent) 
SwingUtilities.isMiddleMouseButton(MouseEvent anEvent)

喜欢:

if(SwingUtilities.isLeftMouseButton(evt)){
// do your work
}
// same for right and middle mouse key

但是如果你想检查鼠标点击的位置

Java Swing is an old technology, it supports the traditional mouse wheel rotation events.

所以我认为它不可能产生差异 b/w 点击发生在触摸板的差异位置上。

来自MouseEvent
没有办法获得鼠标点击的位置。

据我所知,没有办法做到这一点。当您单击触控板时,触控板将简单地显示自己,就好像按下了 mouse1 一样。键盘对于 left/right shift 等有不同的键码...我不相信 "trackpad click" 和 "mouse 1".

有不同的键码

无论如何,您为什么要添加只有笔记本电脑用户(并且只有某些笔记本电脑用户)才能使用的功能。台式机呢?手机呢?