黑马程序员_Java Robot 实用技术
????今天打开我的QQ音乐,胡乱的翻着些什么,突然发现我不知在啥地方上网中病毒了,给我QQ上的所有好友都发了一个钓鱼信息...
????? ? 有图有真相
?
着实恼火,开始删了一会儿,发现实在是太多了,于是突然想起,Java中有个Robot这个类,不是很熟悉,查了一下官方文档,用法很简单,只有几个方法,今天我用到的是其中的几个方法
public void?mouseMove(int?x, int?y)Moves mouse pointer to given screen coordinates.
?public void mouseRelease(int?buttons)Releases one or more mouse buttons.
public void?delay(int?ms)Sleeps for the specified time. To catch any?InterruptedException
s that occur,?Thread.sleep()
?may be used instead.
public void?mousePress(int?buttons)Presses one?or more mouse buttons. The mouse buttons should be released using the?mouseRelease
?method.
?就上面这几个方法已经够用了,移动鼠标,按下鼠标,放开鼠标,停一会儿,等网络响应,再移动鼠标,按下鼠标,放开鼠标。一次删除动作完成,重复N次,就轻松搞定了。??
Robot robot=new Robot(); int x1=971,y1=524; int x2=880,y2=510; for (int i = 0; i < 500; i++) { robot.mouseMove(x1, y1); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(500); robot.mouseMove(x2, y2); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(1000); }?