首页 > 代码库 > 苦 工工工工
苦 工工工工
package cn.andros230.netty; /* * Copyright 2012 The Netty Project * * The Netty Project licenses this file to you under the Apache License, * version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ import java.awt.AWTException; import java.awt.MouseInfo; import java.awt.Point; import java.awt.Robot; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; public class ObjectEchoServerHandler extends ChannelInboundHandlerAdapter { private int mouseX; private int mouseY; private Robot robot; public ObjectEchoServerHandler() throws AWTException { robot = new Robot(); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { cause.printStackTrace(); ctx.close(); } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws AWTException { Data data = (Data) msg; //System.out.println(data.getX()+" "+data.getY()); if (data.getType().equals("down")) { Point point = MouseInfo.getPointerInfo().getLocation(); mouseX = (int) point.getX(); mouseY = (int) point.getY(); } if (data.getType().equals("move")) { robot.mouseMove(mouseX + (-data.getX()), mouseY + (-data.getY())); robot.setAutoDelay(10); } if (data.getType().equals("up")) { System.out.println("单击"); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); } if (data.getType().equals("long")) { robot.mousePress(InputEvent.BUTTON3_MASK); robot.mouseRelease(InputEvent.BUTTON3_MASK); } } }
苦 工工工工
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。