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

Ctrl+C does not generate VK_CANCEL KEY_TYPED KeyEvent

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 6
    • client-libs
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
      but running under JRE 1.6.0

      ADDITIONAL OS VERSION INFORMATION :
      Linux mymachinename 2.6.12-1-k7-smp #1 SMP Tue Aug 9 14:38:47 UTC 2005 i686 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      In previous versions of the JRE and on different platforms, a VK_CANCEL KEY_TYPED KeyEvent is generated when Ctrl+C is typed on a component. However, this does not seem to be the case when running JRE 1.6.0 on Linux.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a new Swing GUI with a JFrame.
      2. Attach a KeyListener to the JFrame.
      3. Show the JFrame.
      4. Put focus in the JFrame.
      5. Observe the calls to the KeyListener when typing Ctrl+C.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expect to get KeyEvents where getKeyChar() returns KeyEvent.VK_CANCEL.
      ACTUAL -
      No VK_CANCEL events are produced.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;

      public class CancelTest {

          private void showGUI() {
              JFrame myFrame = new JFrame();
              myFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
              myFrame.setLayout(new BorderLayout());
              myFrame.setSize(400,300);
              myFrame.addKeyListener(new CancelKeyListener());
              myFrame.setVisible(true);
          }

          private class CancelKeyListener extends KeyAdapter {
              public void keyTyped(KeyEvent e) {
                  System.out.println("keyTyped");
                  if (e.getKeyChar() == KeyEvent.VK_CANCEL) {
                      System.out.println("keyTyped: VK_CANCEL");
                  }
              }

              public void keyPressed(KeyEvent e) {
                  System.out.println("keyPressed");
                  if (e.getKeyChar() == KeyEvent.VK_CANCEL) {
                      System.out.println("keyPressed: VK_CANCEL");
                  }
              }
          }

          public static void main(String[] args) {
              final CancelTest myCancelTest = new CancelTest();
              SwingUtilities.invokeLater(new Runnable() {
                      public void run() {
                          myCancelTest.showGUI();
                      }
                  }
                  );
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      One workaround is to check for the Ctrl+C manually on Linux. That is, check for VK_CANCEL, but also if running on a Linux machine, check that getKeyChar() returns either 'c' or 'C' and that ((getModifiers() & KeyEvent.CTRL_MASK) != 0).

      Release Regression From : 5.0u10
      The above release value was the last known release where this
      bug was not reproducible. Since then there has been a regression.

            Unassigned Unassigned
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: