java鼠标点击事件_java 触发鼠标点击事件 向linux发送指令

packageclick;importjava.awt.AWTException;importjava.awt.MouseInfo;importjava.awt.Point;importjava.awt.Robot;importjava.awt.event.InputEvent;importjava.awt.event.KeyEvent;importjava.io.BufferedReader;importjava.io.InputStreamReader;importjava.util.Properties;importcom.jcraft.jsch.ChannelExec;importcom.jcraft.jsch.JSch;importcom.jcraft.jsch.JSchException;importcom.jcraft.jsch.Session;public classclick {public static void main(String[] args) throwsException {//获取鼠标位置//for(int i=0;i<10;i++){//Point point = MouseInfo.getPointerInfo().getLocation();//System.out.println("x=" + point.getX() + ",y="+ point.getY());//Thread.sleep(3000);//}

Robot robot = null;

robot= newRobot();int x=298;int y = 133;for(int i=0;i<500;i++)

{if(i%20 ==0){

String cmdStop= "service activator stop";

String cmdStart= "service activator start";newclick().sendCommand(cmdStop);

Thread.sleep(180000);newclick().sendCommand(cmdStart);

Thread.sleep(180000);

Thread.sleep(3000);int jobx = 1333;int joby = 634;

robot.mouseMove(jobx,joby);

robot.mousePress(InputEvent.BUTTON1_MASK);//模拟鼠标松开左键

robot.mouseRelease(InputEvent.BUTTON1_MASK);

robot.keyPress(KeyEvent.VK_BACK_SPACE);

robot.keyRelease(KeyEvent.VK_BACK_SPACE);

robot.keyPress(KeyEvent.VK_BACK_SPACE);

robot.keyRelease(KeyEvent.VK_BACK_SPACE);

System.out.println("----------------");

}

robot.mouseMove(x, y);

robot.mousePress(InputEvent.BUTTON1_MASK);//模拟鼠标松开左键

robot.mouseRelease(InputEvent.BUTTON1_MASK);

Thread.sleep(120000);

System.out.println("----"+i);

}

}public void sendCommand(String cmd) throwsException {

System.out.println(cmd);

String userName="root";

String pass="NFVD1234";

String ip="16.17.101.33";

JSch sshSingleton= newJSch();

Session session=sshSingleton.getSession(userName, ip);

session.setPassword(pass);

Properties config= newProperties();

config.put("StrictHostKeyChecking", "no");

session.setConfig(config);

session.connect();

ChannelExec channel= (ChannelExec) session.openChannel("exec");

BufferedReader in= new BufferedReader(newInputStreamReader(

channel.getInputStream()));

channel.setCommand(cmd);

channel.connect();//读取命令输出信息

String msg;while ((msg = in.readLine()) != null) {

System.out.println(msg);

}

channel.disconnect();

session.disconnect();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值