2012-09-27 52 views
0

我写了一个php代码并构建了一个jar文件。通过PHP我发送参数到jar文件。在jar文件中,我基本上用scanner - nextLine读取参数。毫秒后自动按回车键java

我的问题是,我怎样才能实现这样的代码,就像一个输入键能够继续该程序?当我发送参数时,让我说10毫秒后,java会自动按键。

感谢您的任何提前。

回答

1

robot类可以在java中为你做这个。这里是一个excample如何使用它。

0

我会使用停止字符,而不是模拟按钮单击。 追加一个通常在您的php生成的字符串中找不到的特殊字符,并让您的扫描器逐字符读取它,直到找到特殊字符。

Java代码:

boolean found = false; 
String parameter = ""; 
Scanner sc = new Scanner(System.in); 
    while(!found){ 
     String input = sc.next(); 
     parameter += input + "\n"; 
     if(input.contains('<specialchar>') 
      found = true; 
    } 
Thread.CurrentThread().wait(10); 
//here goes the code to deal with finished input 

希望这有助于

0

根据我的理解,使用getKeyCode()检查KeyEvent或在10毫秒后直接将KeyCode作为硬编码传递。

0
$('textarea').bind("enterKey",function(e){ 
//do stuff here 
});