很久之前百度的,所以忘记了作者,所以仅作为自己的日记纪录在此:
package com.robot.test;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
public class TestRobot {
public static void main(String[] args) {
try {
System.out.println("===");
clear();
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void clear() throws AWTException
{
Robot r = new Robot();
r.mousePress(InputEvent.BUTTON3_MASK); // 按下鼠标右键
r.mouseRelease(InputEvent.BUTTON3_MASK); // 释放鼠标右键
r.keyPress(KeyEvent.VK_CONTROL); // 按下Ctrl键
r.keyPress(KeyEvent.VK_R); // 按下R键
r.keyRelease(KeyEvent.VK_R); // 释放R键
r.keyRelease(KeyEvent.VK_CONTROL); // 释放Ctrl键
r.delay(100);
}
}