Name: krC82822 Date: 04/19/2001
java -version 1.3
While using java.awt.Robot to enter Keyboard characters into a webpage (with
help from a Virtual Keyboard), I find that the Robot class takes only KeyCodes
as parameters for its keyPress() method. This becomes a stumbling block if you
want to do translate that Keyboard as you have to let the Robot class know the
keycode value.
JButton button0 = new KeyButton();
button0.setHorizontalTextPosition(JButton.CENTER);
button0.setVerticalTextPosition(JButton.CENTER);
Kb.put(button0, new KeyEvent(button0, KeyEvent.KEY_PRESSED,
System.currentTimeMillis(), InputEvent.META_MASK,
KeyEvent.VK_BACK_QUOTE));
add(button0);
.
.
.
.
class KeyButton extends JButton
{
public KeyButton()
{
}
protected void processMouseEvent(MouseEvent e)
{
e.consume();
KeyEvent keyEvent = (KeyEvent) Kb.get(e.getSource());
if (keyEvent.getKeyCode() != KeyEvent.VK_SHIFT)
{
if (e.getID() == MouseEvent.MOUSE_PRESSED)
{
((KeyButton) e.getSource()).setSelected(true);
}
else if (e.getID() == MouseEvent.MOUSE_RELEASED)
{
((KeyButton) e.getSource()).setSelected(false);
}
if (e.getID() == MouseEvent.MOUSE_CLICKED)
{
if (keyEvent != null)
{
/*
* This is where the problem lies. Since we give a
* specific keycode, it becomes difficult to do so
* while doing translations.
*/
robot.keyPress(keyEvent.getKeyCode());
}
}
}
}
}
--------
19 Apr 2001, eval1127@eng -- see also # 4347983
(Review ID: 121017)
======================================================================