How to convert String to KeyInput for Robot


2006-01-18 01:56:49 PM
jbuilder1
Hello all:
I use the following snippet to demo how to write down a string on some place
of screen.
For example: If I want to write down 'robot', I have to get the array
keyInput first.
My question is to find an easy to automatically convert a given string to
corresponding
keyInput.
Does java provide such function for us?
Thank you
-Daniel
//Store Keystrokes in an array
static int keyInput[] = {KeyEvent.VK_R,KeyEvent.VK_O,
KeyEvent.VK_B,KeyEvent.VK_O,KeyEvent.VK_T};
Robot robot = new Robot();
//This types the word 'robot' in the Textarea
for (int i = 0; i < keyInput.length; i++)
{
if(i>0)
{
robot.keyRelease(KeyEvent.VK_SHIFT);
}
robot.keyPress(keyInput[i]);
robot.delay(500);
}