-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
None
-
beta2
-
x86
-
linux
All the keys I have tried work fine, except VK_END. No KeyEvents at all
are generated for VK_END - not press or release. Not
Everything is fine on Solaris, but not on Linux.
/* RobotInvalidKeyCodeBug.java 18/05/2000
*/
/* How to reproduce the Bug? -------->
Run this sample code. You would see a frame with a red Canvas.
This is an automated test. No user interaction allowed.
The robot will press the above mentioned keys.
If key events are triggered, the message will be displayed
on the text area.
If Invalid Key Code Exception is thrown, the bug is reproduced.
*/
/* Description : KeyPressed, KeyReleased not triggered for dead keys
*/
import java.awt.*;
import java.awt.event.*;
public class RobotKey extends Frame implements KeyListener, FocusListener {
Label lblTitle = new Label();
TextArea txtOutput;
Panel testPanel;
Canvas canvas;
Robot robot;
boolean keyPressed, keyReleased;
// gotFocus tells us whether the Canvas got the focus
boolean gotFocus = false;
int testKeys[] = {
KeyEvent.VK_Q,
KeyEvent.VK_INSERT,
KeyEvent.VK_END,
KeyEvent.VK_W
};
public RobotKey(String title) {
super(title);
//Initialize Robot
try {
robot = new Robot();
}
catch (AWTException awte) {
System.out.println("Exception : " + awte);
}
// Add Title Label
lblTitle.setBackground(Color.yellow);
add(lblTitle,BorderLayout.NORTH);
testPanel = new Panel();
testPanel.setBackground(Color.yellow);
canvas = new Canvas();
canvas.setBackground(Color.red);
canvas.setSize(100,100);
testPanel.add(canvas);
canvas.addKeyListener(this);
canvas.addFocusListener(this);
//Add Output Text Area
txtOutput = new TextArea(18,25);
add(txtOutput,BorderLayout.SOUTH);
addWindowListener(new WindowEventHandler(this));
add(testPanel);
setSize(750,420);
setVisible(true);
txtOutput.setText(
"This is an automated test. No user interaction allowed \n");
doTest();
}
public void doTest() {
canvas.requestFocus();
while (true) {
robot.delay(1000);
if (gotFocus) {
System.err.println("Canvas got focus");
break;
}
System.err.println("Don't have focus yet - click on red square");
}
keyPressed = false;
keyReleased = false;
for(int i=0; i<testKeys.length; i++) {
lblTitle.setText("Robot Testing for " +
KeyEvent.getKeyText(testKeys[i]) + " Key");
robot.delay(1000);
try {
robot.keyPress(testKeys[i]);
} catch (IllegalArgumentException e) {
txtOutput.append("\nFAIL : Invalid Key Code : " + testKeys[i] +
" , " + KeyEvent.getKeyText(testKeys[i])+ "\n" + e + "\n");
txtOutput.setCaretPosition(txtOutput.getText().length());
continue;
}
robot.delay(500);
if (keyPressed) {
txtOutput.append("\nPASS : KeyPressed triggered for " +
KeyEvent.getKeyText(testKeys[i]));
} else {
txtOutput.append("\nFAIL : KeyPressed is not triggered for " +
KeyEvent.getKeyText(testKeys[i]));
}
txtOutput.setCaretPosition(txtOutput.getText().length());
keyPressed = false;
try {
robot.keyRelease(testKeys[i]);
} catch (IllegalArgumentException e) {
txtOutput.append("\nFAIL : Invalid Key Code : " + testKeys[i] +
" , " + KeyEvent.getKeyText(testKeys[i])+ "\n" + e + "\n");
txtOutput.setCaretPosition(txtOutput.getText().length());
continue;
}
robot.delay(500);
if (keyReleased) {
txtOutput.append("\nPASS : KeyReleased triggered for " +
KeyEvent.getKeyText(testKeys[i]));
} else {
txtOutput.append("\nFAIL : KeyReleased is not triggered for " +
KeyEvent.getKeyText(testKeys[i]));
}
txtOutput.setCaretPosition(txtOutput.getText().length());
keyReleased = false;
}
}
// KEY LISTENER
public void keyTyped(KeyEvent e) {
txtOutput.append("\n"+e.toString());
txtOutput.setCaretPosition(txtOutput.getText().length());
System.out.println(e + "\n");
}
public void keyPressed(KeyEvent e) {
txtOutput.append("\n"+e.toString());
txtOutput.setCaretPosition(txtOutput.getText().length());
System.out.println(e + "\n");
keyPressed = true;
}
public void keyReleased(KeyEvent e) {
txtOutput.append("\n"+e.toString());
txtOutput.setCaretPosition(txtOutput.getText().length());
System.out.println(e + "\n");
keyReleased = true;
}
public void focusGained(FocusEvent e) {
gotFocus = true;
System.err.println("FocusListener: gotFocus");
}
public void focusLost(FocusEvent e) {
gotFocus = false;
System.err.println("FocusListener: lostFocus");
}
public static void main(String args[]) {
RobotKey s = new RobotKey("Robot Invalid Key Code Test");
}
}
// Listens for windowevents triggered by the main frame.
class WindowEventHandler extends WindowAdapter {
Frame f = null;
public WindowEventHandler(Frame input) {
f=input;
}
public void windowClosing(WindowEvent w) {
f.dispose();
System.exit(0);
}
}
are generated for VK_END - not press or release. Not
Everything is fine on Solaris, but not on Linux.
/* RobotInvalidKeyCodeBug.java 18/05/2000
*/
/* How to reproduce the Bug? -------->
Run this sample code. You would see a frame with a red Canvas.
This is an automated test. No user interaction allowed.
The robot will press the above mentioned keys.
If key events are triggered, the message will be displayed
on the text area.
If Invalid Key Code Exception is thrown, the bug is reproduced.
*/
/* Description : KeyPressed, KeyReleased not triggered for dead keys
*/
import java.awt.*;
import java.awt.event.*;
public class RobotKey extends Frame implements KeyListener, FocusListener {
Label lblTitle = new Label();
TextArea txtOutput;
Panel testPanel;
Canvas canvas;
Robot robot;
boolean keyPressed, keyReleased;
// gotFocus tells us whether the Canvas got the focus
boolean gotFocus = false;
int testKeys[] = {
KeyEvent.VK_Q,
KeyEvent.VK_INSERT,
KeyEvent.VK_END,
KeyEvent.VK_W
};
public RobotKey(String title) {
super(title);
//Initialize Robot
try {
robot = new Robot();
}
catch (AWTException awte) {
System.out.println("Exception : " + awte);
}
// Add Title Label
lblTitle.setBackground(Color.yellow);
add(lblTitle,BorderLayout.NORTH);
testPanel = new Panel();
testPanel.setBackground(Color.yellow);
canvas = new Canvas();
canvas.setBackground(Color.red);
canvas.setSize(100,100);
testPanel.add(canvas);
canvas.addKeyListener(this);
canvas.addFocusListener(this);
//Add Output Text Area
txtOutput = new TextArea(18,25);
add(txtOutput,BorderLayout.SOUTH);
addWindowListener(new WindowEventHandler(this));
add(testPanel);
setSize(750,420);
setVisible(true);
txtOutput.setText(
"This is an automated test. No user interaction allowed \n");
doTest();
}
public void doTest() {
canvas.requestFocus();
while (true) {
robot.delay(1000);
if (gotFocus) {
System.err.println("Canvas got focus");
break;
}
System.err.println("Don't have focus yet - click on red square");
}
keyPressed = false;
keyReleased = false;
for(int i=0; i<testKeys.length; i++) {
lblTitle.setText("Robot Testing for " +
KeyEvent.getKeyText(testKeys[i]) + " Key");
robot.delay(1000);
try {
robot.keyPress(testKeys[i]);
} catch (IllegalArgumentException e) {
txtOutput.append("\nFAIL : Invalid Key Code : " + testKeys[i] +
" , " + KeyEvent.getKeyText(testKeys[i])+ "\n" + e + "\n");
txtOutput.setCaretPosition(txtOutput.getText().length());
continue;
}
robot.delay(500);
if (keyPressed) {
txtOutput.append("\nPASS : KeyPressed triggered for " +
KeyEvent.getKeyText(testKeys[i]));
} else {
txtOutput.append("\nFAIL : KeyPressed is not triggered for " +
KeyEvent.getKeyText(testKeys[i]));
}
txtOutput.setCaretPosition(txtOutput.getText().length());
keyPressed = false;
try {
robot.keyRelease(testKeys[i]);
} catch (IllegalArgumentException e) {
txtOutput.append("\nFAIL : Invalid Key Code : " + testKeys[i] +
" , " + KeyEvent.getKeyText(testKeys[i])+ "\n" + e + "\n");
txtOutput.setCaretPosition(txtOutput.getText().length());
continue;
}
robot.delay(500);
if (keyReleased) {
txtOutput.append("\nPASS : KeyReleased triggered for " +
KeyEvent.getKeyText(testKeys[i]));
} else {
txtOutput.append("\nFAIL : KeyReleased is not triggered for " +
KeyEvent.getKeyText(testKeys[i]));
}
txtOutput.setCaretPosition(txtOutput.getText().length());
keyReleased = false;
}
}
// KEY LISTENER
public void keyTyped(KeyEvent e) {
txtOutput.append("\n"+e.toString());
txtOutput.setCaretPosition(txtOutput.getText().length());
System.out.println(e + "\n");
}
public void keyPressed(KeyEvent e) {
txtOutput.append("\n"+e.toString());
txtOutput.setCaretPosition(txtOutput.getText().length());
System.out.println(e + "\n");
keyPressed = true;
}
public void keyReleased(KeyEvent e) {
txtOutput.append("\n"+e.toString());
txtOutput.setCaretPosition(txtOutput.getText().length());
System.out.println(e + "\n");
keyReleased = true;
}
public void focusGained(FocusEvent e) {
gotFocus = true;
System.err.println("FocusListener: gotFocus");
}
public void focusLost(FocusEvent e) {
gotFocus = false;
System.err.println("FocusListener: lostFocus");
}
public static void main(String args[]) {
RobotKey s = new RobotKey("Robot Invalid Key Code Test");
}
}
// Listens for windowevents triggered by the main frame.
class WindowEventHandler extends WindowAdapter {
Frame f = null;
public WindowEventHandler(Frame input) {
f=input;
}
public void windowClosing(WindowEvent w) {
f.dispose();
System.exit(0);
}
}