using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Threading;using TCPCommunication;namespace RemoteDeskClient{ public partial class Form1 : Form { TCPClientSocket _tcpClientSocket; TCPClientSender _tcpClientSender; MyDataClientAnalyse _myDataClientAnalyse; MyDataClientDeal _myDataClientDeal; GlobalHook _gloabalhook; System.Threading.Timer _timer; bool _monitor = false; //监控状态 public Form1() { InitializeComponent(); _tcpClientSocket = new TCPClientSocket(); _tcpClientSender = new TCPClientSender(_tcpClientSocket); _myDataClientAnalyse = new MyDataClientAnalyse(_tcpClientSocket); _myDataClientDeal = new MyDataClientDeal(_myDataClientAnalyse); _timer = new System.Threading.Timer(new TimerCallback(TimerCallBack), null, 0, 100); _tcpClientSocket.ConnectResponsed = new ConnectResponsedEventHandler(_tcpClientSocket_ConnectResponsed); _tcpClientSocket.DisConnected = new DisConnectedEventHandler(_tcpClientSocket_DisConnected); _myDataClientDeal.SimulateKeybdDown = new SimulateKeybdDownEventHandler(_myDataClientDeal_SimulateKeybdDown); _myDataClientDeal.SimulateKeybdUp = new SimulateKeybdUpEventHandler(_myDataClientDeal_SimulateKeybdUp); _myDataClientDeal.SimulateMouseLeftDown = new SimulateMouseLeftDownEventHandler(_myDataClientDeal_SimulateMouseLeftDown); _myDataClientDeal.SimulateMouseLeftUp = new SimulateMouseLeftUpEventHandler(_myDataClientDeal_SimulateMouseLeftUp); _myDataClientDeal.SimulateMouseMove = new SimulateMouseMoveEventHandler(_myDataClientDeal_SimulateMouseMove); _myDataClientDeal.SimulateMouseRightDown = new SimulateMouseRightDownEventHandler(_myDataClientDeal_SimulateMouseRightDown); _myDataClientDeal.SimulateMouseRightUp = new SimulateMouseRightUpEventHandler(_myDataClientDeal_SimulateMouseRightUp); _myDataClientDeal.SimulateMouseWheel = new SimulateMouseWheelEventHandler(_myDataClientDeal_SimulateMouseWheel); _myDataClientDeal.StartMonitor = new StartMonitorEventHandler(_myDataClientDeal_StartMonitor); _myDataClientDeal.StopMonitor = new StopMonitorEventHandler(_myDataClientDeal_StopMonitor); //钩子消耗系统性能 注销掉钩子代码后 服务端无法监控鼠标和键盘输入信息 //_gloabalhook = new GlobalHook(); //_gloabalhook.KeyDown = new KeyEventHandler(_gloabalhook_KeyDown); //_gloabalhook.KeyUp = new KeyEventHandler(_gloabalhook_KeyUp); //_gloabalhook.OnMouseActivity = new MouseEventHandler(_gloabalhook_OnMouseActivity); _myDataClientDeal.Start(); } #region socket状态 void _tcpClientSocket_ConnectResponsed(System.Net.EndPoint remoteEP, bool result) { if (result) { _monitor = true; } } void _tcpClientSocket_DisConnected() { _monitor = false; } #endregion #region 钩子 void _gloabalhook_OnMouseActivity(object sender, MouseEventArgs e) { if (_monitor) { if (e.Button == MouseButtons.Left) { _tcpClientSender.SendString(Msg.ZMsg5, ""); //左键按下 _tcpClientSender.SendString(Msg.ZMsg6, ""); //左键松开 } if (e.Button == MouseButtons.Right) { _tcpClientSender.SendString(Msg.ZMsg7, ""); //右键按下 _tcpClientSender.SendString(Msg.ZMsg8, ""); //右键松开 } if (e.Button == MouseButtons.None && e.Delta == 0) { _tcpClientSender.SendString(Msg.ZMsg4, e.X " " e.Y); //鼠标位置 } //if (e.Delta == 0) //{ // _tcpClientSender.SendString(Msg.ZMsg9, e.Delta.ToString()); //鼠标滚动 //} } } void _gloabalhook_KeyUp(object sender, KeyEventArgs e) { if (_monitor) { _tcpClientSender.SendString(Msg.ZMsg3, e.KeyData.ToString()); } } void _gloabalhook_KeyDown(object sender, KeyEventArgs e) { if (_monitor) { _tcpClientSender.SendString(Msg.ZMsg2, e.KeyData.ToString()); } } #endregion #region 数据处理 void _myDataClientDeal_StopMonitor(string extrainfo, string remoteIP, int remotePort) { _monitor = false; } void _myDataClientDeal_StartMonitor(string extrainfo, string remoteIP, int remotePort) { _monitor = true; } void _myDataClientDeal_SimulateMouseWheel(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseWheel(int.Parse(infos[2]), int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseRightUp(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseRightUp(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseRightDown(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseRigthDown(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseMove(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseMove(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseLeftUp(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseLeftUp(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseLeftDown(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseLeftDown(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateKeybdUp(string keyinfo, string remoteIP, int remotePort) { NativeMethods.KeybdUp(keyinfo); } void _myDataClientDeal_SimulateKeybdDown(string keyinfo, string remoteIP, int remotePort) { NativeMethods.KeybdDown(keyinfo); } #endregion #region 屏幕截图 private void TimerCallBack(object obj) { if (_monitor) { Bitmap b = PrintSystemScreen(); _tcpClientSender.SendObject(Msg.ZMsg1, b); } } #endregion private void Form1_Load(object sender, EventArgs e) { } private Bitmap PrintSystemScreen() { Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics screenG = Graphics.FromImage(bmp); screenG.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy); return bmp; } private void button1_Click(object sender, EventArgs e) { _tcpClientSocket.Start(textBox1.Text, 9999); } }}
下载tcp 远程桌面实例源码用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论