按下F1键之后自动执行下面robot类代码的模拟按键操作,按一次就执行一次,再按再执行一次。
import java.awt.Robot;import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JTextField;
public class jf {
static JTextField a = new JTextField();
public static <keypoint> void main(String arg[]) throws Exception {
// ts.addKeyListener(new KeyAdapter() {
a.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
while (true) {
if (e.getKeyCode() == KeyEvent.VK_F1) {
break;
//当我在桌面任何一个地方按下F1键之后自动执行下面robot类代码的模拟按键操作,按一次就执行一次,再按再执行一次。
}
}
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
});
Robot r = new Robot();
r.delay(3000);
for (int i = 1; i <= 6; i++) {
r.keyPress(KeyEvent.VK_UP);
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_C);
r.keyRelease(KeyEvent.VK_CONTROL);
r.keyRelease(KeyEvent.VK_C);
r.keyPress(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_V);
r.keyRelease(KeyEvent.VK_CONTROL);
r.keyRelease(KeyEvent.VK_V);
r.keyPress(KeyEvent.VK_RIGHT);
}
r.keyPress(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_HOME);
}
}