【问题标题】:automatically press enter key after milliseconds java毫秒后自动按回车键java
【发布时间】:2012-09-19 03:19:36
【问题描述】:

我已经编写了一个 php 代码并构建了一个 jar 文件。通过 php 我将参数发送到 jar 文件。在 jar 文件中,我基本上使用扫描仪读取参数 - nextLine。

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

感谢您的提前。

【问题讨论】:

    标签: java php jar key enter


    【解决方案1】:

    我会使用停止字符,而不是模拟按钮点击。 附加一个通常在 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
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      robot 类可以在 java 中为您执行此操作。这是excample 的使用方法。

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          【解决方案4】:
          $('textarea').bind("enterKey",function(e){
           //do stuff here
          });
          

          【讨论】:

            猜你喜欢
            • 2019-08-02
            • 2010-11-05
            • 1970-01-01
            • 2017-05-27
            • 2018-10-26
            • 2015-06-23
            • 2016-08-26
            • 2014-06-08
            • 1970-01-01
            相关资源
            最近更新 更多