-
Bug
-
Resolution: Unresolved
-
P4
-
8, 8u20
-
In Review
-
x86
-
windows
FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.2.9200]
EXTRA RELEVANT SYSTEM CONFIGURATION :
No additional configuration required.
A DESCRIPTION OF THE PROBLEM :
I have a problem with KeyEvents when Alt+NumPad method is used to input characters. The generated KeyEvents contains random characters when ALT key is pressed.
This is a serious problem, because the java.awt.Robot or the barcode scanners does not work when ALT method is needed, for example outside the USA, where the keyboards are different. The JRE generates random numbers instead of the correct barcode sequences.
The issue exists in older version of Java. I have found it in Java 7 also. The actual test client is very simple, the application is only a JFrame containing a JTextField and a JTextArea.
This problem does not depend of the source of the character inputs it occurs when we use a java.awt.Robot object or a barcode scanner that can emulate ALT method.
ADDITIONAL REGRESSION INFORMATION:
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
There are many different ways to reproduce this bug:
One way:
1) Create a JFrame with a JTextArea
2) Create a java.awt.Robot object
3) Make the Robot press the ALT key
4) Make the Robot press and release the ALT codes
5) Make the Robot release the ALT key
6) You will see random numbers in the JTextArea instead of the correct ones coded by the ALT codes
Another way:
1) Create a simple Java program that creates a JFrame with a JTextArea
2) Run the program
3) Get a simple, commonly used barcode scanner
4) Set the scanner to use ALT method
5) Scan some barcodes with the scanner
6) You will see random numbers in the JTextArea instead of the correct barcodes. Use NotePad to see the correct barcode.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the correct characters to appeare in the JTextArea, coded by the ALT numbers.
ACTUAL -
Sometimes random characters apeare in the JTextArea.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
There are no error messages.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package javaapplication1;
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Robot;
import static java.awt.event.KeyEvent.VK_ALT;
import static java.awt.event.KeyEvent.VK_ENTER;
import static java.awt.event.KeyEvent.VK_NUMPAD0;
import static java.awt.event.KeyEvent.VK_NUMPAD1;
import static java.awt.event.KeyEvent.VK_NUMPAD2;
import static java.awt.event.KeyEvent.VK_NUMPAD3;
import static java.awt.event.KeyEvent.VK_NUMPAD4;
import static java.awt.event.KeyEvent.VK_NUMPAD5;
import static java.awt.event.KeyEvent.VK_NUMPAD6;
import static java.awt.event.KeyEvent.VK_NUMPAD7;
import static java.awt.event.KeyEvent.VK_NUMPAD8;
import static java.awt.event.KeyEvent.VK_NUMPAD9;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
/**
*
* @author Fece
*/
public class JavaApplication1 {
private static final String TEST = "5@WM010$|";
private static final int DELAY = 50;
private static final Map<Character, int[]> ALT_CODES = new HashMap<Character, int[]>();
static {
ALT_CODES.put('5', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD5, VK_NUMPAD3});
ALT_CODES.put('@', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD6, VK_NUMPAD4});
ALT_CODES.put('W', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD7, VK_NUMPAD7});
ALT_CODES.put('M', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD8, VK_NUMPAD7});
ALT_CODES.put('0', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD4, VK_NUMPAD8});
ALT_CODES.put('1', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD4, VK_NUMPAD9});
ALT_CODES.put('$', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD3, VK_NUMPAD6});
ALT_CODES.put('|', new int[]{VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD4});
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
// TODO code application logic here
System.out.println(java.nio.charset.Charset.defaultCharset().name());
final int delay = DELAY;
final JFrame frame = new JFrame("ScannerTest");
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane scrollPane = new JScrollPane(new JTextArea());
scrollPane.setPreferredSize(new Dimension(300, 600));
frame.add(scrollPane);
frame.pack();
frame.setVisible(true);
}
});
new Thread() {
@Override
public void run() {
try {
Robot robot = new Robot();
for (int c = 0; c < 1000; c++) {
if (frame.isActive()) {
for (int i = 0; i < TEST.length(); i++) {
int[] codes = ALT_CODES.get(TEST.charAt(i));
if (frame.isActive()
&& !(codes == null || codes.length == 0)) {
robot.keyPress(VK_ALT);
for (int code : codes) {
robot.keyPress(code);
robot.keyRelease(code);
}
robot.keyRelease(VK_ALT);
}
robot.delay(delay);
}
robot.keyPress(VK_ENTER);
robot.keyRelease(VK_ENTER);
} else {
c--;
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
} catch (AWTException e) {
e.printStackTrace();
}
}
}.start();
} catch (InterruptedException ex) {
Logger.getLogger(JavaApplication1.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvocationTargetException ex) {
Logger.getLogger(JavaApplication1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
---------- END SOURCE ----------
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.2.9200]
EXTRA RELEVANT SYSTEM CONFIGURATION :
No additional configuration required.
A DESCRIPTION OF THE PROBLEM :
I have a problem with KeyEvents when Alt+NumPad method is used to input characters. The generated KeyEvents contains random characters when ALT key is pressed.
This is a serious problem, because the java.awt.Robot or the barcode scanners does not work when ALT method is needed, for example outside the USA, where the keyboards are different. The JRE generates random numbers instead of the correct barcode sequences.
The issue exists in older version of Java. I have found it in Java 7 also. The actual test client is very simple, the application is only a JFrame containing a JTextField and a JTextArea.
This problem does not depend of the source of the character inputs it occurs when we use a java.awt.Robot object or a barcode scanner that can emulate ALT method.
ADDITIONAL REGRESSION INFORMATION:
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
There are many different ways to reproduce this bug:
One way:
1) Create a JFrame with a JTextArea
2) Create a java.awt.Robot object
3) Make the Robot press the ALT key
4) Make the Robot press and release the ALT codes
5) Make the Robot release the ALT key
6) You will see random numbers in the JTextArea instead of the correct ones coded by the ALT codes
Another way:
1) Create a simple Java program that creates a JFrame with a JTextArea
2) Run the program
3) Get a simple, commonly used barcode scanner
4) Set the scanner to use ALT method
5) Scan some barcodes with the scanner
6) You will see random numbers in the JTextArea instead of the correct barcodes. Use NotePad to see the correct barcode.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the correct characters to appeare in the JTextArea, coded by the ALT numbers.
ACTUAL -
Sometimes random characters apeare in the JTextArea.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
There are no error messages.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package javaapplication1;
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Robot;
import static java.awt.event.KeyEvent.VK_ALT;
import static java.awt.event.KeyEvent.VK_ENTER;
import static java.awt.event.KeyEvent.VK_NUMPAD0;
import static java.awt.event.KeyEvent.VK_NUMPAD1;
import static java.awt.event.KeyEvent.VK_NUMPAD2;
import static java.awt.event.KeyEvent.VK_NUMPAD3;
import static java.awt.event.KeyEvent.VK_NUMPAD4;
import static java.awt.event.KeyEvent.VK_NUMPAD5;
import static java.awt.event.KeyEvent.VK_NUMPAD6;
import static java.awt.event.KeyEvent.VK_NUMPAD7;
import static java.awt.event.KeyEvent.VK_NUMPAD8;
import static java.awt.event.KeyEvent.VK_NUMPAD9;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
/**
*
* @author Fece
*/
public class JavaApplication1 {
private static final String TEST = "5@WM010$|";
private static final int DELAY = 50;
private static final Map<Character, int[]> ALT_CODES = new HashMap<Character, int[]>();
static {
ALT_CODES.put('5', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD5, VK_NUMPAD3});
ALT_CODES.put('@', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD6, VK_NUMPAD4});
ALT_CODES.put('W', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD7, VK_NUMPAD7});
ALT_CODES.put('M', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD8, VK_NUMPAD7});
ALT_CODES.put('0', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD4, VK_NUMPAD8});
ALT_CODES.put('1', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD4, VK_NUMPAD9});
ALT_CODES.put('$', new int[]{VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD3, VK_NUMPAD6});
ALT_CODES.put('|', new int[]{VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD4});
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
// TODO code application logic here
System.out.println(java.nio.charset.Charset.defaultCharset().name());
final int delay = DELAY;
final JFrame frame = new JFrame("ScannerTest");
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane scrollPane = new JScrollPane(new JTextArea());
scrollPane.setPreferredSize(new Dimension(300, 600));
frame.add(scrollPane);
frame.pack();
frame.setVisible(true);
}
});
new Thread() {
@Override
public void run() {
try {
Robot robot = new Robot();
for (int c = 0; c < 1000; c++) {
if (frame.isActive()) {
for (int i = 0; i < TEST.length(); i++) {
int[] codes = ALT_CODES.get(TEST.charAt(i));
if (frame.isActive()
&& !(codes == null || codes.length == 0)) {
robot.keyPress(VK_ALT);
for (int code : codes) {
robot.keyPress(code);
robot.keyRelease(code);
}
robot.keyRelease(VK_ALT);
}
robot.delay(delay);
}
robot.keyPress(VK_ENTER);
robot.keyRelease(VK_ENTER);
} else {
c--;
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
} catch (AWTException e) {
e.printStackTrace();
}
}
}.start();
} catch (InterruptedException ex) {
Logger.getLogger(JavaApplication1.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvocationTargetException ex) {
Logger.getLogger(JavaApplication1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
---------- END SOURCE ----------
- relates to
-
JDK-8307942 Alt+NumPad entry does not work reliably and can produce garbled text
- Open
-
JDK-8270529 Inaccurate KeyTyped value when scanning a barcode with 'GS' character
- Open