2012-09-27 50 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 
});