JDK-4262044 : in KeyEvent there exists no KeyCode for '+' (61=0x3C)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.2.2
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-08-12
  • Updated: 1999-12-15
  • Resolved: 1999-12-15
Related Reports
Relates :  
Description

Name: rlT66838			Date: 08/12/99


Pressing the '+'-Button, the Programm fires a KeyEvent with 
KeyCode==61 (=0x3C), but the class KeyEvent does not contain any constant
VK_xxx=0x3C.
Furthermore VK_PLUS==0x0209

 If you type '+' into the TextField, you will see that the KeyCode triggered is 61 while
KeyEvent.VK_PLUS = 521.

----------Test Case---------------

import java.awt.event.*;
import javax.swing.JFrame; ,
import javax.swing.JTextField;

public class KeyBug extends JFrame
{
	JTextField feld;
	
	public KeyBug()
	{
		feld = new JTextField();
		feld.addKeyListener(new KeyAdapter()
		{
			public void keyPressed(KeyEvent evt)
			{
				System.out.println("KeyCode=" + evt.getKeyCode());
				System.out.println("KeyChar=" + evt.getKeyChar());
			}
		});
		this.getContentPane().add(java.awt.BorderLayout.NORTH, feld);
		this.pack();
		this.show();
	}
	
	public static void main(String[] args)
	{
		System.out.println("PLUS - KeyCode: " + KeyEvent.VK_PLUS);
		KeyBug keyBug = new KeyBug();
	}
}

(Review ID: 93517) 
======================================================================

Comments
EVALUATION It looks like there is some (understandable) confusion here, and the docs may need some cleaning up. keyPressed() (as used in the included test case) is used for low-level reporting of key events. This reports when keys are pressed, and includes events for modifier keys. In the case of the '+' symbol, it is generated either by typing shift-'=' (in which case the KeyEvent passed into keyPressed() will have a key code of VK_SHIFT followed by another KeyEvent with VK_EQUALS (0x3D == 61) or by typing '+" on the numeric keypad, in which case the KeyCode is VK_ADD. keyTyped() is the higher-level key processing method. KeyCodes are not set in KeyEvents passed into keyTyped(). Shift-'=' and numeric '+' generate identical KeyEvents from the perspective of keyTyped(). getKeyChar() is probably the method to use to see if a '+' has been typed. I would close this bug if it weren't for the fact that I was unable to generate a VK_PLUS under any circumstances. It is not clear what this constant refers to, and also unclear from the documentation that VK_ADD refers to the '+' on the numeric keypad. If VK_PLUS is never used, this should definitely be documented, if not deprecated (can a constant be deprecated?) or removed. WinNT4 and Solaris performed the same under kestrel-beta-N, other than Windows generating continuous keyPressed() events while the shift key is held down whereas Solaris generates just one. brent.christian@eng 1999-08-12 The VK_PLUS keycode is used by non-US keyboards in which the '+' key exists on the primary layer. On US keyboards it is on the secondary layer, so it cannot be generated. The names VK_ADD and VK_PLUS follow the standard naming convention for mapping keys to keycodes used on both windows and Unix: VK_PLUS for the standard keys and VK_ADD for the numeric keypad. Just one further clarification: the submitter incorrectly translated 61 as 0x3c. 61 is actually 0x3d. eric.hawkes@eng 1999-08-13
13-08-1999