Robot robot = new Robot();
TimerTask task = new TimerTask()
{
public void run()
{
robot.keyPress(KeyEvent.VK_ENTER);
System.out.println( "time out. exit..." );
}
};
Timer timer = new Timer();
timer.schedule( task, 10*1000 );
Scanner sc = new Scanner(System.in);
String in = sc.nextLine();
timer.cancel();
System.out.println(in);
I'm trying to think how can I input 'enter' without pressing enter button when the time limit arrived at 10 seconds.
so I'm going to input lots of character as many as possible util the time ends. And I want to save that String into 'in'
I just found that Robot class can press enter key, but I don't think I use it in right way.