aTest
来源:互联网 发布:奢悦水光针网络传销 编辑:程序博客网 时间:2024/06/01 16:50
package aTest;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.*;
public class ThreadTest extends Thread {
private static Robot robot = null;
public void run() {
for (;;) {
robot.keyPress(KeyEvent.VK_F1);
robot.keyRelease(KeyEvent.VK_F1);
try {
sleep(5 * 1000);
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
public static void main(String[] args) {
Thread t = new ThreadTest();
char exit = ' ';
t.setDaemon(true);
try {
//产生一个 Robot 类别的物件
robot = new Robot();
}catch (AWTException e){
System.err.println(e.toString());
}
t.start();
while (exit != 'Q' && exit != 'q') {
try {
System.out.println("Press Q/q to exit:");
exit = (char) System.in.read();
} catch (IOException e) {
}
}
System.out.println("Process finished.");
}
}