实例介绍
【实例简介】
【实例截图】
【核心代码】
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);
}
}
}
好例子网口号:伸出你的我的手 — 分享!
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论