【发布时间】:2012-09-19 03:19:36
【问题描述】:
我已经编写了一个 php 代码并构建了一个 jar 文件。通过 php 我将参数发送到 jar 文件。在 jar 文件中,我基本上使用扫描仪读取参数 - nextLine。
我的问题是,我怎样才能实现这样的代码,就像 Enter 键能够继续程序?当我发送参数时,让我说10毫秒后,java会自动按键。
感谢您的提前。
【问题讨论】:
我已经编写了一个 php 代码并构建了一个 jar 文件。通过 php 我将参数发送到 jar 文件。在 jar 文件中,我基本上使用扫描仪读取参数 - nextLine。
我的问题是,我怎样才能实现这样的代码,就像 Enter 键能够继续程序?当我发送参数时,让我说10毫秒后,java会自动按键。
感谢您的提前。
【问题讨论】:
我会使用停止字符,而不是模拟按钮点击。 附加一个通常在 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
希望对你有帮助
【讨论】:
据我了解,使用 getKeyCode() 检查 KeyEvent 或在 10 毫秒后直接将 KeyCode 作为硬编码传递。
【讨论】:
$('textarea').bind("enterKey",function(e){
//do stuff here
});
【讨论】: