【VS2010 C# 代码】实时监控鼠标位置和左键点击时的位置

上传者: r00_a2lbur | 上传时间: 2021-08-20 15:46:57 | 文件大小: 44KB | 文件类型: RAR
Microsoft Visual Studio 2010做的C#实时监控鼠标位置和左键点击时的位置实例,主要代码: public class MouseHook { private Point point; private Point Point { get { return point; } set { if (point != value) { point = value; if (MouseMoveEvent != null) { var e = new MouseEventArgs(MouseButtons.None, 0, point.X, point.Y, 0); MouseMoveEvent(this, e); } } } } private int hHook; private const int WM_LBUTTONDOWN = 0x201; public const int WH_MOUSE_LL = 14; public Win32Api.HookProc hProc; public MouseHook() { this.Point = new Point(); } public int SetHook() { hProc = new Win32Api.HookProc(MouseHookProc); hHook = Win32Api.SetWindowsHookEx(WH_MOUSE_LL, hProc, IntPtr.Zero, 0); return hHook; } public void UnHook() { Win32Api.UnhookWindowsHookEx(hHook); } private int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam) { Win32Api.MouseHookStruct MyMouseHookStruct = (Win32Api.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32Api.MouseHookStruct)); if (nCode < 0) { return Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam); } else { if (MouseClickEvent != null) { MouseButtons button = MouseButtons.None; int clickCount = 0; switch ((Int32)wParam) { case WM_LBUTTONDOWN: button = MouseButtons.Left; clickCount = 1; break; } var e = new MouseEventArgs(button, clickCount, point.X, point.Y, 0); MouseClickEvent(this, e); } this.Point = new Point(MyMouseHookStruct.pt.x, MyMouseHookStruct.pt.y); return Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam); } } public delegate void MouseMoveHandler(object sender, MouseEventArgs e); public event MouseMoveHandler MouseMoveEvent; public delegate void MouseClickHandler(object sender, MouseEventArgs e); public event MouseClickHandler MouseClickEvent; }

文件下载

资源详情

[{"title":"( 25 个子文件 44KB ) 【VS2010 C# 代码】实时监控鼠标位置和左键点击时的位置","children":[{"title":"Demo_mousehook_csdn","children":[{"title":"Demo_mousehook_csdn.suo <span style='color:#111;'> 19.00KB </span>","children":null,"spread":false},{"title":"Demo_mousehook_csdn.sln <span style='color:#111;'> 899B </span>","children":null,"spread":false},{"title":"Demo_mousehook_csdn","children":[{"title":"bin","children":[{"title":"Debug","children":[{"title":"Demo_mousehook_csdn.vshost.exe.manifest <span style='color:#111;'> 490B </span>","children":null,"spread":false},{"title":"Demo_mousehook_csdn.exe <span style='color:#111;'> 12.00KB </span>","children":null,"spread":false},{"title":"Demo_mousehook_csdn.pdb <span style='color:#111;'> 29.50KB </span>","children":null,"spread":false},{"title":"Demo_mousehook_csdn.vshost.exe <span style='color:#111;'> 11.33KB </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"Form1.Designer.cs <span style='color:#111;'> 2.97KB </span>","children":null,"spread":false},{"title":"Program.cs <span style='color:#111;'> 500B </span>","children":null,"spread":false},{"title":"obj","children":[{"title":"x86","children":[{"title":"Debug","children":[{"title":"Demo_mousehook_csdn.exe <span style='color:#111;'> 12.00KB </span>","children":null,"spread":false},{"title":"GenerateResource.write.1.tlog <span style='color:#111;'> 978B </span>","children":null,"spread":false},{"title":"Demo_mousehook_csdn.pdb <span style='color:#111;'> 29.50KB </span>","children":null,"spread":false},{"title":"DesignTimeResolveAssemblyReferencesInput.cache <span style='color:#111;'> 6.28KB </span>","children":null,"spread":false},{"title":"DesignTimeResolveAssemblyReferences.cache <span style='color:#111;'> 2.11KB </span>","children":null,"spread":false},{"title":"GenerateResource.read.1.tlog <span style='color:#111;'> 416B </span>","children":null,"spread":false},{"title":"TempPE","children":null,"spread":false},{"title":"Demo_mousehook_csdn.Properties.Resources.resources <span style='color:#111;'> 180B </span>","children":null,"spread":false},{"title":"Demo_mousehook_csdn.Form1.resources <span style='color:#111;'> 180B </span>","children":null,"spread":false},{"title":"Demo_mousehook_csdn.csproj.FileListAbsolute.txt <span style='color:#111;'> 1.12KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true},{"title":"Form1.cs <span style='color:#111;'> 5.22KB </span>","children":null,"spread":false},{"title":"Form1.resx <span style='color:#111;'> 5.68KB </span>","children":null,"spread":false},{"title":"Demo_mousehook_csdn.csproj <span style='color:#111;'> 3.61KB </span>","children":null,"spread":false},{"title":"Properties","children":[{"title":"Resources.resx <span style='color:#111;'> 5.48KB </span>","children":null,"spread":false},{"title":"Settings.settings <span style='color:#111;'> 249B </span>","children":null,"spread":false},{"title":"AssemblyInfo.cs <span style='color:#111;'> 1.36KB </span>","children":null,"spread":false},{"title":"Settings.Designer.cs <span style='color:#111;'> 1.08KB </span>","children":null,"spread":false},{"title":"Resources.Designer.cs <span style='color:#111;'> 2.82KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true}]

评论信息

  • jiangyc112 :
    很不错哦~很实用的代码
    2017-10-14

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明