如何让windows中的程序自动执行?(就像自动演示,robot)

newman0708 2002-06-06 03:02:54
请问各位高手,如何将windows中的程序自动执行,就像自动演示(相当于robot类型)

比如象新建文件用ctrl+N,但是怎么用程序实现。(不光指新建还有别的。)

...全文
109 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
newman0708 2002-06-07
  • 打赏
  • 举报
回复
fightboy的程序很好,不知其它人还有没有例子?
fightboy 2002-06-07
  • 打赏
  • 举报
回复
以上是个例子,仓促写成,请多指教

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test extends JFrame {
private JButton button = new JButton("show dialog ...");
private String message = "Please Enter Your Name";

public Test() {
super("Test Robot");
Container contentPane = getContentPane();

contentPane.setLayout(new BorderLayout());
contentPane.add(button,BorderLayout.CENTER);

setLocation(400,300);
setSize(200,100);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String s = JOptionPane.showInputDialog(message);

if(s == null)
JOptionPane.showMessageDialog(Test.this,"cancel button activated");
else
JOptionPane.showMessageDialog(Test.this,"Name: " + s);
}
});
}

public static void moveSmooth(Robot robot,
int x1, int y1,
int x2, int y2,
int stop)
{
for(int i = 0;i<stop;i++)
{
robot.mouseMove(x1+(x2-x1)/stop*i,y1+(y2-y1)/stop*i);
robot.delay(100);
}
}

public static void main(String[] args) throws Exception
{
Test test = new Test();
test.show();
Robot robot = new Robot();
robot.delay(5000);
moveSmooth(robot,200,200,500,350,30);
robot.delay(1000);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(200);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.waitForIdle();
robot.setAutoDelay(200);
robot.keyPress(KeyEvent.VK_F);
robot.keyRelease(KeyEvent.VK_F);
robot.keyPress(KeyEvent.VK_I);
robot.keyRelease(KeyEvent.VK_I);
robot.keyPress(KeyEvent.VK_G);
robot.keyRelease(KeyEvent.VK_G);
robot.keyPress(KeyEvent.VK_H);
robot.keyRelease(KeyEvent.VK_H);
robot.keyPress(KeyEvent.VK_T);
robot.keyRelease(KeyEvent.VK_T);
robot.keyPress(KeyEvent.VK_B);
robot.keyRelease(KeyEvent.VK_B);
robot.keyPress(KeyEvent.VK_O);
robot.keyRelease(KeyEvent.VK_O);
robot.keyPress(KeyEvent.VK_Y);
robot.keyRelease(KeyEvent.VK_Y);
robot.delay(2000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}
}
fightboy 2002-06-06
  • 打赏
  • 举报
回复
java.awt
Class Robot
java.lang.Object
|
+-java.awt.Robot

public class Robot
extends Object
This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. The primary purpose of Robot is to facilitate automated testing of Java platform implementations.


使用这个类完全可以满足你的要求
turbochen 2002-06-06
  • 打赏
  • 举报
回复
不知你是想用java自动运行windows程序,还是想写一个windows的程序自动运行?
如果是后者,不知你要用哪种语言?
如果是前者,我觉得不太实际,为什么要这么做?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧