public void do_keyboard(){
Robot robot = null;
try {
robot = new Robot();
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //创建一个robot对象
keyPress(robot, KeyEvent.VK_X); //按下x键
robot.delay(1000);
keyPress(robot, KeyEvent.VK_X); //按下x键
robot.delay(1000);
keyPress(robot, KeyEvent.VK_X); //按下x键
robot.delay(1000);
keyPress(robot, KeyEvent.VK_X); //按下x键
robot.delay(1000);
}
public static void keyPressWithShift(Robot r, int key) {
r.keyPress(KeyEvent.VK_SHIFT);
r.keyPress(key);
r.keyRelease(key);
r.keyRelease(KeyEvent.VK_SHIFT);
r.delay(100);
}
// ctrl+ 按键
public static void keyPressWithCtrl(Robot r, int key) {
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(key);
r.keyRelease(key);
r.keyRelease(KeyEvent.VK_CONTROL);
r.delay(100);
}
// alt+ 按键
public static void keyPressWithAlt(Robot r, int key) {
r.keyPress(KeyEvent.VK_ALT);
r.keyPress(key);
r.keyRelease(key);
r.keyRelease(KeyEvent.VK_ALT);
r.delay(100);
}
//单个 按键
public static void keyPress(Robot r,int key){
r.keyPress(key);
r.keyRelease(key);
r.delay(100);
}
do_keyboard();