JDK-4199284 : The '|' (pipe) character cannot be generated on a non-US keyboard within Java
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.6
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1998-12-22
  • Updated: 1999-04-07
  • Resolved: 1999-04-07
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
1.2.2 1.2.2Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
Customer has implemented the patch for bug id 4122687 but is having the 
following problem:

We have implemented the java-level patch listed in bugtraq, and with
the patch in place we are able to successfully accept the AltGr characters.
However there is one character we are still unable to produce.
The '|' (pipe) character cannot be generated on a non-US keyboard within
Java when it is possible from other applications.
On a non-US keyboard this character should be generated by pressing
Alt + 0166 (via Numeric keypad).

TESTCASE:
Directions for running the testcase and the testcase source code are below:

1. Click on the language icon in the system tray. German is DE, English
is EN, French is FR. Select the one you want to activate.

This will switch keyboard layouts for the currently active window
(only). So, you could have several different languages activated in
several different windows at the same time.

2. It's very useful to have the character map application running,
so that you can see what characters require what special key
combinations. The character map application is in Start, Programs,
Accessories, System Tools, Character Map (in Win 98; it's slightly
different in Win95 and NT).

Highlighting a particular character will expand it and display the
key combination needed to generate the character. Be sure that you
have set the language for the character map application to the
desired language.

Key combination for German Pipe character is Alt + 0166 (Numeric keypad).

Below are other key combinations:

Desired Symbol          Key combination
\                       Control + Alt + -
@                       Control + Alt + Q
superscript 2           Control + Alt + Shift + 2
superscript 3           Control + Alt + Shift + 3
[                       Control + Alt + 9
]                       Control + Alt + 0
{                       Control + Alt + 7
}                       Control + Alt +
/                       Shift + 7
~                       Control + Alt + ] (note that the character map incorrectly
                        indicates that this is produced using Control + Alt + +)
|                        

********************************************************************************
TESTCASE
********************************************************************************
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.text.*;

public class AltGraphTest extends JFrame implements ActionListener {
	JTextField textField;
	JButton    applyButton;

	public AltGraphTest() {
		setTitle(getClass().getName());
		textField = new JTextField();
		getContentPane().add(BorderLayout.NORTH, textField);

		applyButton = new JButton("Apply Patch");
		getContentPane().add(BorderLayout.SOUTH, applyButton);
		applyButton.addActionListener(this);

		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}

	public void actionPerformed(ActionEvent e) {
		Object src = e.getSource();
		if (src == applyButton) {
			applyPatch();
			applyButton.setEnabled(false);  // only apply patch once
		}
	}

	public static void main(String args[]) {
		AltGraphTest agt = new AltGraphTest();
		agt.pack();
		agt.show();
	}

	// Recommended workaround for bug 4122687
	public static void applyPatch() {
		Keymap map = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
		if (map != null) {
			map.setDefaultAction(new DefaultKeyTypedAction());
		} else {
			System.err.println("Default keymap doesn't exist, patch not applied");
		}
	}

	/**
	 * The action that is executed by default if 
	 * a <em>key typed event</em> is received and there
	 * is no keymap entry.  There is a variation across
	 * different VM's in what gets sent as a <em>key typed</em>
	 * event, and this action tries to filter out the undesired
	 * events.  This filters the control characters and those
	 * with the ALT modifier.
	 * <p>
	 * If the event doesn't get filtered, it will try to insert
	 * content into the text editor.  The content is fetched
	 * from the command string of the ActionEvent.  The text
	 * entry is done through the <code>replaceSelection</code>
	 * method on the target text component.  This is the
	 * action that will be fired for most text entry tasks.
	 *
	 * @see DefaultEditorKit#defaultKeyTypedAction
	 * @see DefaultEditorKit#getActions
	 * @see Keymap#setDefaultAction
	 * @see Keymap#getDefaultAction
	 */
	static class DefaultKeyTypedAction extends TextAction {
		/**
		 * Creates this object with the appropriate identifier.
		 */
		public DefaultKeyTypedAction() {
			super(DefaultEditorKit.defaultKeyTypedAction);
		}

		/**
		 * The operation to perform when this action is triggered.
		 *
		 * @param e the action event
		 */
		public void actionPerformed(ActionEvent e) {
			JTextComponent target = getTextComponent(e);
			if ((target != null) && (e != null)) {
				String content = e.getActionCommand();
				int mod = e.getModifiers();
				if ((content != null) && (content.length() > 0) &&
				(((mod & ActionEvent.ALT_MASK) == 0) ||
				((mod & ActionEvent.CTRL_MASK) != 0))) {
					char c = content.charAt(0);
					if ((c >= 0x20) && (c != 0x7F)) {
						target.replaceSelection(content);
					}
				}
			}
		}
	}
}

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

SUGGESTED FIX Here are the diffs for this fix. svdiffs 1.212 1.213 awt_Component.cpp 1621c1621 < {java_awt_event_KeyEvent_CHAR_UNDEFINED, 0} --- > {java_awt_event_KeyEvent_VK_UNDEFINED, 0} 1735a1736,1741 > // Windows treats AltGr as Ctrl+Alt > if (modifiers & java_awt_event_InputEvent_ALT_GRAPH_MASK) { > altIsDown = TRUE; > ctrlIsDown = TRUE; > } > 3711c3717 < * Method: handleEvent --- > * Method: nativeHandleEvent 3771a3778,3780 > /* Check to see whether the keyCode or modifiers were changed > on the keyPressed event, and tweak the following keyTyped > event (if any) accodingly. */ 3774a3784,3785 > UINT winKey = pMsg->wParam; > bCharChanged = FALSE; 3776,3778c3787,3789 < if (pMsg->wParam == VK_PROCESSKEY) < { < bCharChanged = FALSE; --- > if (winKey == VK_PROCESSKEY) { > // Leave it up to IME > break; 3780,3786c3791,3796 < else < { < UINT key, keyModifiers; < p->JavaKeyToWindowsKey(keyCode, &key, &keyModifiers); < if (!key) < { < key = keyCode; --- > > if (keyCode != java_awt_event_KeyEvent_VK_UNDEFINED) { > UINT newWinKey, ignored; > p->JavaKeyToWindowsKey(keyCode, &newWinKey, &ignored); > if (newWinKey != 0) { > winKey = newWinKey; 3788,3789d3797 < modifiedChar = p->WindowsKeyToJavaChar(key, modifiers); < bCharChanged = (keyChar != modifiedChar); 3790a3799,3802 > > modifiedChar = p->WindowsKeyToJavaChar(winKey, modifiers); > bCharChanged = (keyChar != modifiedChar); > break; 3791a3804 > break; // not reached 3793d3805 < break; 3797a3810 > 3817c3830,3831 < break; --- > break; // not reached >
11-06-2004

EVALUATION Fixed with 4191924. david.mendenhall@eng 1999-04-05 Fixed by using the native Windows key value in nativeHandleEvent when the keyCode is VK_UNDEFINED. Test case is at /test/java/awt/event/KeyEvent/ExtendedKeysTest eric.hawkes@eng 1999-04-07
07-04-1999