Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4493674

Modifier keys (Ctrl,Shift,Meta and Alt) are not set when held down .

XMLWordPrintable

    • beta3
    • sparc
    • solaris_9
    • Verified

      Platforms : Solaris 9 (64 bit) , Sol2.6 , Sol 2.8 ,Linux
      jdk build : Build 76

      This is happening only on Build 76 . This problem does not occur in Build 74 .

      The following methods return false when the corresponding keys are held down .

      a) isShiftDown()
      b) isControlDown()
      c) isAltDown()
      d) isMetaDown()


      The same test cases works fine on Windows on build 76 .

      Run the following test case on Solaris and Linux platform .
      ======================================================
      import java.awt.*;
      import java.awt.event.ActionListener;
      import java.awt.event.*;

      public class ModifiersTest1 extends Frame implements KeyListener{

              Frame frame;
              Button button;
              TextField textField;

          public ModifiersTest1(){

              frame=new Frame();
              frame.setTitle("Extended Modifiers Test");
              frame.setLayout(new FlowLayout());

              button=new Button("BUTTON");
              textField=new TextField(5);

              button.addKeyListener(this);
              textField.addKeyListener(this);

              frame.add(button);
              frame.add(textField);

              frame.setBackground(Color.red);
              frame.setSize(500,200);
              frame.setVisible(true);
              frame.toFront();

          }

          public void keyPressed(KeyEvent e){
             char typed = e.getKeyChar();
             System.out.println("keyPressed called ");

             if( e.isShiftDown()){
                System.out.println("Shift key is down");
             }
             if(e.isControlDown()){
                System.out.println("Control key is down");
             }
             if(e.isAltDown()){
                System.out.println("Alt key is down");
             }
             if(e.isMetaDown()){
                System.out.println("Meta key is down");
             }
             if(e.isAltGraphDown()){
                System.out.println("AltGraph key is down");
             }
           }

          public void keyTyped(KeyEvent e){
            System.out.println("keyTyped called ");
          }
          public void keyReleased(KeyEvent e){
            System.out.println("keyReleased called ");
          }

         public static void main(String[] args) {
              new ModifiersTest1();
          }

      }
      ================================================================
      Run this program and press on "Shift" key on the button or on the TextField.It should print the following line "Shift Key is Down" . But this is not happening in Build 76 on Solaris and Linux platforms . But on windows it works fine . The same applies to all the other methods(alt,meta and ctrl) listed above .

      I have attached another program which is related to the above .This uses
      the newly added method getModifiersEx() to check for the masks.This works fine on Windows but fails on Solaris and Linux.

      =====
      Added by Vishal Byakod : date( 08/21/2001)

      isAltGraphDown() also returns false . Looks like ALT_GRAPH_DOWN_MASK is also not set when it the respective key is down on an event.

      =========================================================
      This bug is not reproducable on Build 81 . Tested it on Solaris Sparc,Linux and Windows NT/ME.
      Tested for Modifier keys as well as Mouse Buttons.
      ###@###.### 2001-10-03

            ssisunw Ssi Ssi (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: