I m using the following loop , but its only typing the first charecter and the rest as numbers, any idea ?
import java.awt.*;
import javax.swing.KeyStroke;
public class test {
public static void main(String[] args) throws AWTException
{
Robot r = new Robot();
String s = "Face";
for (int i = 0; i < s.length(); i++)
{
char res = s.charAt(i);
r.keyPress(res);
r.keyRelease(res);
r.delay(1000);
}
}
}
OUTPUT typing : F135
The keyPress/Release methods need an int value that represents the character you want to type. These value are the key code for each character as determined by the KeyEvent.VK_??? variables.
Try:
However, even this won’t work for all characters. For example on my keyboard the “%” is above the “5”. You can’t use VK_PERCENT. The key stroke needed is VK_5 along with a shift. There is no way to know the actual mapping of your keyboard to do this automatically.
So a Robot is not a good way to do this.