Reputation: 1
When I try to use an awt robot to type in java nothing comes out,
what am I doing wrong?
I wanted to make something that would just type TEST and a new line after but every time I run it nothing comes out, I wonder what it is that I'm doing wrong. Pardon my nooby code I am new to Java.
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
public class test {
static int msg[] =
{
KeyEvent.VK_T, KeyEvent.VK_E, KeyEvent.VK_S, KeyEvent.VK_T, KeyEvent.VK_ENTER,
};
public static void main(String[] args) throws AWTException, InterruptedException {
Robot r = new Robot();
Thread.sleep(200);
for(int x = 0;x < 10;x++){
for(int i = 0;i < msg.length;i++){
r.keyPress(msg[i]);
r.delay(10);
}
}
}
}
Upvotes: 0
Views: 82
Reputation: 347204
keyPress
with a keyRelease
call (for the same key type)Upvotes: 1
Reputation: 10562
Where is it typing? If it is AWT, you need to get control focus first.
Upvotes: 0