krave 2015-04-24 11:19 采纳率: 0%
浏览 1863

关于Java的runtime的以下代码,如何让notepad保持开着的状态而结束java程序。

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.IOException;

public class Robot05 {
    // Create an array of keycode data
    static int keyInput[] = { KeyEvent.VK_H, KeyEvent.VK_E, KeyEvent.VK_L,
            KeyEvent.VK_L, KeyEvent.VK_O };// end keyInput array

    public static void main(String[] args) throws AWTException, IOException {

        // Start the Windows Notepad program running
        // in a separate process. It should become
        // the active window, capable of accepting
        // input from the keyboard.
        Process proc = Runtime.getRuntime().exec("notepad");

        // Get a Robot object that will be used to
        // enter characters into the Notepad document
        Robot robot = new Robot();

        // Enter the keycodes contained in the
        // keyInput array into the Notepad document.
        // Make the first character upper case and
        // the remaining characters lower case.
        robot.keyPress(KeyEvent.VK_SHIFT);
        for (int cnt2 = 0; cnt2 < keyInput.length; cnt2++) {
            if (cnt2 > 0) {
                robot.keyRelease(KeyEvent.VK_SHIFT);
            }// end if
            robot.keyPress(keyInput[cnt2]);
            // Insert a one-half second delay between
            // characters.
            robot.delay(500);
        }// end for loop
    }// main

}
  • 写回答

3条回答 默认 最新

  • threenewbee 2015-04-24 11:35
    关注

    直接在任务管理器中杀掉程序就可以了。

    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元