一份C#的HOOK类
来源:互联网 发布:matlab 两个矩阵拼接 编辑:程序博客网 时间:2024/06/05 16:15
最近迷上玩手游,然后想写个鼠标宏,奈何网上的东西都不太敢用就自己写吧。这次尝了尝鲜用了C#,C++的Hook写习惯了再用C#感觉有点奇怪- -。
DWORD非得弄成intPtr和Int32,HANDLE非得写成指针实在是尴尬, 我在想64位编译器下直接打int会不会崩掉ORZ
不多说 直接贴代码
class MessageNode { public MessageNode(Int32 _nCode,Int32 _wParam,Int32 _lParam) { lParam = _lParam; wParam = _wParam; nCode = _nCode; Timestamp = DateTime.Now; } /// <summary> /// 时间戳 精确至毫秒 /// </summary> public DateTime Timestamp { get; set; } public Int32 lParam { get; set; } public Int32 wParam { get; set; } public Int32 nCode { get; set; } } class MessageHook { public const int WM_MOUSEMOVE = 0x200; public const int WM_LBUTTONDOWN = 0x201; public const int WM_RBUTTONDOWN = 0x204; public const int WM_MBUTTONDOWN = 0x207; public const int WM_LBUTTONUP = 0x202; public const int WM_RBUTTONUP = 0x205; public const int WM_MBUTTONUP = 0x208; public const int WM_LBUTTONDBLCLK = 0x203; public const int WM_RBUTTONDBLCLK = 0x206; public const int WM_MBUTTONDBLCLK = 0x209; public const int WM_KEYDOWN = 0x100; public const int WM_KEYUP = 0x101; public const int WH_MOUSE_LL = 14; public const int WH_KEYBOARD_LL = 13; public MessageHook() { hHook = 0; messageQueue = new Queue<MessageNode>(); hookMessageSet = new HashSet<int>(); } private Queue<MessageNode> messageQueue; private HashSet<Int32> hookMessageSet; private int hHook; public delegate Int32 HookProc(Int32 nCode, Int32 wParam, Int32 lParam); public static HookProc hookProc; [DllImport("User32.dll")] extern static void UnhookWindowsHookEx(Int32 hWnd); [DllImport("User32.dll")] extern static Int32 SetWindowsHookEx(Int32 hookType, HookProc hookProc, IntPtr hModel, Int32 threadID); [DllImport("User32.dll")] extern static Int32 CallNextHookEx(Int32 hHook, Int32 nCode, Int32 wParam, Int32 lParam); [DllImport("kernel32.dll")] public static extern IntPtr GetModuleHandle(string name); Int32 AddMessageToQueue(Int32 nCode, Int32 wParam, Int32 lParam) { if (hookMessageSet.Contains(wParam)) messageQueue.Enqueue(new MessageNode(nCode, wParam, lParam)); return CallNextHookEx(hHook, nCode, wParam, lParam); } public bool Start(Int32 hookType) { if (hHook != 0) Stop(); hookProc = new HookProc(AddMessageToQueue); IntPtr ptr = GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName); // MessageBox.Show(ptr + ""); hHook = SetWindowsHookEx(hookType, hookProc,ptr , 0); return hHook != 0; } public void Stop() { UnhookWindowsHookEx(hHook); hHook = 0; } public MessageNode GetAMessage() { return messageQueue.Dequeue(); } public void AddHookMessageType(Int32 messageType) { hookMessageSet.Add(messageType); } public bool Empty { get { return messageQueue.Count == 0; } } }
0 0
- 一份C#的HOOK类
- 一份非常棒的inline hook 代码
- c# hook钩子的使用
- .net,c#的一份笔试题
- C# hook
- 关于C#的Hook技术问题
- C# hook的一个简单例子
- 一个C#毕业生如何才能找到一份适当的工作呢?
- 一份关于连接数据库的Util类
- 一份访问SqlServer数据库的Helper类
- 反射拷贝一份新的实体类
- HOOK API的一个类
- Hook钩子C#实例
- C#中使用Hook
- Hook钩子C#实例
- Hook钩子C#实例
- Hook钩子C#实例
- C# 系统钩子--hook
- python中urllib的高级用法
- DNS解析
- Cpp_Primer--异常检测入门
- 关于LeetCode中Palindrome Number一题的理解
- LIGHT OJ 1122 - Digit Count【DP数塔】
- 一份C#的HOOK类
- java web:At least one JAR was scanned for TLDs yet contained no TLDs.
- 显示技术介绍(1)_概述
- stringByAddingPercentEncodingWithAllowedCharacters和CFURLCreateStringByAddingPercentEscapes的使用
- arr索引和值互换
- Spring MVC中常用注解之@SessionAttributes @ModelAttribute详解
- LeetCode--No.190--Reverse Bits
- Gym 101064 D Black Hills golden jewels 二分
- Linux(1)——权限的概念和思想、Linux文件权限与目录管理