模拟鼠标桌面点击(桌面机器人)

/**
 * [Product]
 *     SaaS
 * [Copyright]
 *     Copyright © 2014 xxxx All Rights Reserved.
 * [FileName]
 *     APP.java
 * [History]
 *     Version         Date              Author             Content
 *     -------- --------------- -------------- ------------------------
 *     1.0.0       2014-7-16      superyang         最初版本
 */
package com.ztesoft.zsmart.saas.test;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.event.InputEvent;
/**
 *  聊天窗口置为顶层,并放在屏幕左上角。窗口左、上边缘与屏幕左、上边缘重合
 *  聊天窗口大小 : 613*536(默认)
 * */
public class APP{
 private Robot robot ;
 private Clipboard system;
 
 public APP() throws AWTException{
  robot = new Robot();
  system = Toolkit.getDefaultToolkit().getSystemClipboard();
 }
 
 private void moveMouse(int x,int y){
  robot.mouseMove(x, y);
  robot.delay(300);
 }
 
 private void leftClick(){
  robot.mousePress(InputEvent.BUTTON1_MASK);
  robot.delay(300);
  robot.mouseRelease(InputEvent.BUTTON1_MASK);
 }
 
 private void rightClick(){
  robot.mousePress(InputEvent.BUTTON3_MASK);
  robot.delay(300);
  robot.mouseRelease(InputEvent.BUTTON3_MASK);
 }
 
 public static void main(String[] args) throws AWTException{
  APP app = new APP();
  StringBuffer msg = new StringBuffer();
  long cnt = 0;
  while(true){
   cnt ++;
   //msg = new StringBuffer();
   //msg.append("\r随机消息"+cnt+"    ").append(StringUtil.dateToStr(new Date())+" \r");
   //msg.append("*&@@/wx¥%#刷!@#¥%……分……&*/wx¥#");
   //StringSelection stsel  = new StringSelection(msg.toString());
   //app.getSystem().setContents(stsel, stsel);
   //间隔5s
   app.getRobot().delay(10000);
   //移动鼠标到聊天窗口的输入框
   app.moveMouse(72, 453);
   //鼠标右击
   app.rightClick();
   //移动鼠标到"粘贴"菜单
   app.moveMouse(173,511);
   //选择"粘贴"
   app.leftClick();
   //移动鼠标到"发送"按钮
   app.moveMouse(357,526);
   //发送
   app.leftClick();
  }
 }
 public Robot getRobot() {
  return robot;
 }
 public void setRobot(Robot robot) {
  this.robot = robot;
 }
 public Clipboard getSystem() {
  return system;
 }
 public void setSystem(Clipboard system) {
  this.system = system;
 }
}

 http://www.iteye.com/topic/1138380

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值