借用Java的Robot类库中的键鼠模拟的方法,执行这个操作,首先切换到QQ界面,然后循环粘贴,回车发送消息。
package newtest; import java.awt.*; import java.awt.event.KeyEvent; public class KeyBoard { private Robot robot = null; public KeyBoard(){ try{ robot = new Robot(); }catch (AWTException a){ System.out.println(a.toString()); } } //跳转到需要发送数据的页面,这里选用的是QQ的界面 public void jump(){ robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_ALT); robot.keyRelease(KeyEvent.VK_TAB); } //循环发送剪贴板上的东西 public void send(){ for(int i=0;i<300;i++){ // robot.keyPress(KeyEvent.VK_C); // robot.keyRelease(KeyEvent.VK_C); // robot.keyPress(KeyEvent.VK_Y); // robot.keyRelease(KeyEvent.VK_Y); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyRelease(KeyEvent.VK_V); robot.delay(300); // robot.keyPress(KeyEvent.VK_SPACE); // robot.keyRelease(KeyEvent.VK_SPACE); // // robot.delay(300); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); //设置延时,不然处理速度过快一下子发完了 robot.delay(500); } } public static void main(String[] args) { KeyBoard keyBoard = new KeyBoard(); keyBoard.jump(); keyBoard.send(); } }