资源简介
java自带的java.net.*和java.awt.robot.* 的混合可以用于实现通过网络对另一台计算机的远程控制,其中包括控制远程计算机鼠标的动作和键盘的输入,可以教大家如何掌握这个技术。
代码片段和文件信息
package steady;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.objectInputStream;
import java.io.objectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
public class fasterClient {
private static Socket socket;
private static objectOutputStream OOS ;
private static objectInputStream OIS;
private static Robot robot;
public static void main(String[] args) throws UnknownHostException IOException AWTException InterruptedException {
// TODO Auto-generated method stub
try{
StartConnection(“s“1);
robotThread robot= new robotThread(OIS);
Thread t = new Thread(robot“robot“);
t.start();
while(true){
CapturePic();
}}
catch(Exception a){
OOS.close();
socket.close();
}}
public static void StartConnection(String IPint port) throws UnknownHostException IOException AWTException{
socket = new Socket(“192.168.0.106“7777);
if(socket.isConnected()){
System.out.println(“socket connected...“+socket);
}
OOS = new objectOutputStream(socket.getOutputStream());
OIS = new objectInputStream(socket.getInputStream());
}
public static void CapturePic() throws AWTException IOException{
robot= new Robot();
Message msg = null;
Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
java.awt.Dimension dm =tk.getScreenSize();
java.awt.Robot robot = new java.awt.Robot();
for (int i = 0; i < 50; i++) {
//截取指定大小的屏幕区域
Rectangle rec = new Rectangle(0 0 (int) dm.getWidth() (int) dm
.getHeight());
BufferedImage bimage = robot.createScreenCapture(rec);
//将图片保存到文件中
String filePath = “D:\\OUT\\screenshot“+i+“.jpeg“;
FileOutputStream fops =new FileOutputStream(filePath);
javax.imageio.ImageIO.write(bimage “jpeg“ fops);
fops.flush();
fops.close();
msg =new Message(filePath);
System.out.println(msg.getFileName());
System.out.println(“send“);
OOS.writeobject(msg);
OOS.flush();
}
}
public static void Close() throws IOException{
OOS.flush();
OOS.close();
socket.close();
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 301 2016-08-18 18:52 RomoteControl\.classpath
文件 393 2016-08-18 18:52 RomoteControl\.project
文件 598 2016-08-18 18:52 RomoteControl\.settings\org.eclipse.jdt.core.prefs
文件 1818 2016-08-18 19:16 RomoteControl\bin\CodeDownLoadFromCSDNbut_not_functionable\Client$1.class
文件 1017 2016-08-18 19:16 RomoteControl\bin\CodeDownLoadFromCSDNbut_not_functionable\Client$2.class
文件 987 2016-08-18 19:16 RomoteControl\bin\CodeDownLoadFromCSDNbut_not_functionable\Client$3.class
文件 2999 2016-08-18 19:16 RomoteControl\bin\CodeDownLoadFromCSDNbut_not_functionable\Client.class
文件 1106 2016-08-18 19:15 RomoteControl\bin\CodeDownLoadFromCSDNbut_not_functionable\ClientDealob
文件 986 2016-08-18 19:15 RomoteControl\bin\CodeDownLoadFromCSDNbut_not_functionable\ClientDealob
文件 1066 2016-08-18 19:15 RomoteControl\bin\CodeDownLoadFromCSDNbut_not_functionable\ClientDealob
文件 1344 2016-08-18 19:15 RomoteControl\bin\CodeDownLoadFromCSDNbut_not_functionable\ClientDealob
文件 5916 2016-08-18 19:15 RomoteControl\bin\CodeDownLoadFromCSDNbut_not_functionable\ClientDealob
文件 726 2016-08-18 19:15 RomoteControl\bin\CodeDownLoadFromCSDNbut_not_functionable\MyException.class
文件 3414 2016-08-18 19:17 RomoteControl\bin\learningMaterial\client.class
文件 3167 2016-08-18 19:08 RomoteControl\bin\learningMaterial\client_onlyExecuteControl.class
文件 3480 2016-08-18 19:10 RomoteControl\bin\learningMaterial\client_only_receive_pic_SLOW.class
文件 3729 2016-08-18 19:17 RomoteControl\bin\learningMaterial\fasterClient.class
文件 1510 2016-08-18 19:10 RomoteControl\bin\learningMaterial\Message.class
文件 2627 2016-08-18 19:14 RomoteControl\bin\learningMaterial\RobotTest.class
文件 2524 2016-08-18 19:17 RomoteControl\bin\learningMaterial\robotThread.class
文件 3386 2016-08-18 19:14 RomoteControl\bin\learningMaterial\ScreenTest.class
文件 4693 2016-08-18 19:17 RomoteControl\bin\learningMaterial\server.class
文件 847 2016-08-18 19:17 RomoteControl\bin\learningMaterial\ServerwithListener$1.class
文件 731 2016-08-18 19:17 RomoteControl\bin\learningMaterial\ServerwithListener$2.class
文件 807 2016-08-18 19:17 RomoteControl\bin\learningMaterial\ServerwithListener$3.class
文件 1073 2016-08-18 19:17 RomoteControl\bin\learningMaterial\ServerwithListener$4.class
文件 5833 2016-08-18 19:17 RomoteControl\bin\learningMaterial\ServerwithListener.class
文件 1011 2016-08-18 19:09 RomoteControl\bin\learningMaterial\server_only_sendControl$1.class
文件 891 2016-08-18 19:09 RomoteControl\bin\learningMaterial\server_only_sendControl$2.class
文件 971 2016-08-18 19:09 RomoteControl\bin\learningMaterial\server_only_sendControl$3.class
............此处省略26个文件信息
评论
共有 条评论