JDK-4174399 : KeyEvent modifiers not working on unix platforms
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.6,1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris_2.6
  • CPU: generic,sparc
  • Submitted: 1998-09-17
  • Updated: 1999-07-20
  • Resolved: 1999-07-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other
1.1.8 1.1.8Fixed 1.2.2Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description

Name: mf23781			Date: 09/17/98


*Symptoms:

Upon testing the supplied code I found that the problem occurs on
Solaris with JDK1.1.6 and AIX JDK1.1.6 but works OK on WinNT with JDK 1.1.6

The keyEvent methods e.g. isAltDown, isControlDown, isShiftDown
do not work, except on Windows platforms.

Applet and html provided below, I've also created an Application version.




*Test case:

//------------------------------------------------------------------------------------------------------------------------------------
// html file keyTest.html follows:
//
<APPLET CODE=keyTest.class WIDTH=350 HEIGHT=350>
</APPLET>


//------------------------------------------------------------------------------------------------------------------------------------
// applet code keyTest.java follows:
//
import java.awt.*;
import java.applet.*;
import java.awt.event.ActionListener;
import java.awt.event.*;

public class keyTest extends Applet implements KeyListener{
    TextArea ta;
    TextField tf;
    String theText;

    public void init(){
	setFont(new Font("Dialog",Font.PLAIN,12));
	ta = new TextArea(8,30);
	tf = new TextField(30);
	tf.addKeyListener(this);
	ta.addKeyListener(this);
//	ta.setText("Hello");
//	tf.setText("abcThere4567");
	add(ta);
	add(tf);
	setBackground(Color.white);
    }

public void keyTyped(KeyEvent e)  { }
   public void keyReleased(KeyEvent e) { }

  public void keyPressed(KeyEvent evt)
   {
      char keyChar = evt.getKeyChar();
      System.out.println("Key typed = " + keyChar); 
      
      if ( evt.isShiftDown() ) {
         System.out.println("Modifier: Shift key is down");
      }
      if ( evt.isControlDown()) {
         System.out.println("Modifier: Control key is down");
      }
      if ( evt.isAltDown() ) {
         System.out.println("Modifier: Alt key is down");
      }
      if ( evt.isMetaDown() ) {
         System.out.println("Modifier: Meta key is down");
      }         
        
   }
   
 private void handleEnter()
   {
      System.out.println("Enter key pressed!!");
   }  

  
    public void paint(Graphics g) {
	g.drawString("Use the alt or shift or ctrl modifier key when typing.",10,200);
	g.drawString("Modifier only works with some keys (backspace is one)", 10,220);
    }

    public void start() {
    }
}



//------------------------------------------------------------------------------------------------------------------------------------
// Application version keyTest2.java follows:
//
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.*;

public class keyTest2 extends Frame implements KeyListener{
    TextArea ta;
    TextField tf;
    String theText;

    public void init(){
        setLayout(new GridLayout(0,1));
        setFont(new Font("Dialog",Font.PLAIN,12));
        ta = new TextArea(8,30);
        tf = new TextField(30);
        tf.addKeyListener(this);
        ta.addKeyListener(this);
//      ta.setText("Hello");
//      tf.setText("abcThere4567");
        add(ta);
        add(tf);
        setBackground(Color.white);
        setSize(400,200);
    }

    public static void main(String[] args)
    {
        keyTest2 kt2 = new keyTest2();
        kt2.init();
        kt2.show();
    }

    public void keyTyped(KeyEvent e)  { }
    public void keyReleased(KeyEvent e) { }

    public void keyPressed(KeyEvent evt)
    {
       char keyChar = evt.getKeyChar();
       System.out.println("Key typed = " + keyChar);

       if ( evt.isShiftDown() ) {
          System.out.println("Modifier: Shift key is down");
       }
       if ( evt.isControlDown()) {
          System.out.println("Modifier: Control key is down");
       }
       if ( evt.isAltDown() ) {
          System.out.println("Modifier: Alt key is down");
       }
       if ( evt.isMetaDown() ) {
          System.out.println("Modifier: Meta key is down");
       }
       if ( (keyChar == 'X') || (keyChar == 'x')) {
          System.exit(0);
       }
    }

}

======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.1.8 FIXED IN: 1.1.8 1.2.2 INTEGRATED IN: 1.1.8 1.2.2 VERIFIED IN: 1.1.8
14-06-2004

EVALUATION This defect is a result of a feature or bug in Motif. When a KeyPress event is received the state of this event is not set. When a KeyRelease event is received the state is set (state equates to modifiers in java.) (See comments.) Fixable by checking for modifiers key press and making the appropriate update to modifiers. aboyd@netscapesrv 1998-11-17 I think this is only a partial fix. Modifiers are now set correctly for KEY_PRESSED and KEY_RELEASED events but not for KEY_TYPED events. This is demonstrated by the following test case: import java.awt.*; import java.awt.event.*; public class ModifierTest extends Frame implements KeyListener{ TextArea ta; public ModifierTest() { ta = new TextArea(8, 30); ta.addKeyListener(this); add(ta); pack(); show(); } public static void main(String[] args) { new ModifierTest(); } public void keyPressed(KeyEvent e) { System.out.println(e); } public void keyReleased(KeyEvent e) { System.out.println(e); } public void keyTyped(KeyEvent evt) { System.out.println(evt); } } Example output when pressing Shift-A (1.1.8G on Solaris) java.awt.event.KeyEvent[KEY_PRESSED,keyCode=16,keyChar='',modifiers=Shift] on text0 java.awt.event.KeyEvent[KEY_PRESSED,keyCode=65,keyChar='A',modifiers=Shift] on text0 java.awt.event.KeyEvent[KEY_TYPED,keyCode=0,keyChar='A'] on text0 java.awt.event.KeyEvent[KEY_RELEASED,keyCode=65,keyChar='A',modifiers=Shift] on text0 java.awt.event.KeyEvent[KEY_RELEASED,keyCode=16,keyChar='',modifiers=Shift] on text0 stuart.lawrence@eng 1999-02-08 ---------------------------------------------------------------- This bug was verified as fixed via manual testing using jdk118h. al.smith@eng 1999-02-26
08-02-1999

SUGGESTED FIX Change handleKeyEvent in canvas.c so that when a KeyPress is recieved, if the key is a modifier key, then update the modifiers value accordingly. aboyd@netscapesrv 1998-11-17
17-11-1998