JDK-4469573 : Incorrect mouse event modifiers with scroll mice
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-06-13
  • Updated: 2001-12-18
  • Resolved: 2001-12-18
Related Reports
Duplicate :  
Description

Name: yyT116575			Date: 06/13/2001


java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

This problems seems to exist only on scroll mice. The modifiers for buttons
other than the left one are incorrect. For instance pressing the middle
button (i.e., the wheel) results in the 'Alt Ctrl Button2' modifier being
"posted" and similarly for the right button. I am seeing this behaviour on
a bog-standard Logitech scroll mouse; it is probably generic.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class T2 extends JScrollPane implements MouseListener {

  private JTextArea jt;
    
  public T2() {
    super();
    setViewportView(jt = new JTextArea());
    jt.setEditable(false);
    jt.addMouseListener(this);
    setPreferredSize(new Dimension(150,100));
  }

  public void mouseClicked (MouseEvent e) { }
  public void mouseReleased(MouseEvent e) { }
  public void mouseEntered (MouseEvent e) { }
  public void mouseExited  (MouseEvent e) { }
  public void mousePressed (MouseEvent e) {
    int mod = e.getModifiers();
    int button =
        ((mod & MouseEvent.BUTTON1_MASK) != 0) ? 1 :
        ((mod & MouseEvent.BUTTON2_MASK) != 0) ? 2 :
        ((mod & MouseEvent.BUTTON3_MASK) != 0) ? 3 : -1;
    StringBuffer buf = new StringBuffer();
    if ((mod & InputEvent.ALT_MASK)   != 0) buf.append("Alt ");
    if ((mod & InputEvent.CTRL_MASK)  != 0) buf.append("Ctrl ");
    if ((mod & InputEvent.META_MASK)  != 0) buf.append("Meta ");
    if ((mod & InputEvent.SHIFT_MASK) != 0) buf.append("Shift ");
    buf.append("Button "+button+"\n");
    jt.append(buf.toString());
  }
	
  public static final void main(String[] argv) {
    JFrame jf = new JFrame();
    jf.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0); 
      }
    });
    jf.getContentPane().add(new T2(), BorderLayout.CENTER);
    jf.pack();
    jf.setVisible(true);
  }
}
(Review ID: 126455) 
======================================================================

Comments
WORK AROUND Name: yyT116575 Date: 06/13/2001 none ====================================================================== In 1.4, the new _DOWN_ modifiers can be used. For pre-1.4, KeyListeners can by used to keep track of when modifier keys are pressed/released. ###@###.### 2001-12-17
17-12-2001

EVALUATION This happens with all mice, and the problem is with the modifier masks themselves. ALT_MASK and BUTTON2_MASK have the same value, as do META_MASK and BUTTON3_MASK. This was originally to help support mice with < 3 buttons, but prevents telling the difference between the ALT key and BUTTON2 in MouseEvents. In 1.4, an additional set of modifiers (the so-called "_DOWN_" modifiers) have been added, which do not overlap - ALT_DOWN_MASK and BUTTON2_DOWN_MASK have distinct values. See bug 4421515. ###@###.### 2001-12-17
17-12-2001