I don't know why I'm having an issue with this. I want the Robot class to type out a string one character at a time as if I were sitting at the keyboard and doing it myself. There will be many, variable strings to type. Here is what I tried to do and it fails miserably:
private String myString = "example";
// Loop for each character in the string
for(int i=0; i<numChars; i++)
{
// Get the current character
myChar = myString.charAt(i);
// Convert the character to a keycode
myKC = (int)myChar;
// Press the key, release the key
myRobot.keyPress(myKC);
myRobot.delay(10);
myRobot.keyRelease(myKC);
}
When I run it, I get some unexpected output in the Notepad window I have open. Instead of it spelling out "example", it gives me something entirely different:
e - instead of 'e', it gives me a '5'
x - instead of 'x', it gives me nothing at all
a - instead of 'a', it gives me a '1'
m - instead of 'm', it gives me a '-'
p - instead of 'p', 'F1' is triggered and the Notepad help window pops open
l - instead of 'l', it gives me nothing at all
e - instead of 'e', it gives me another '5'
What am I doing wrong here? This was supposed to be easy...
Edited by: ConQuesimo on Jan 19, 2010 12:06 AM