c#中通过设置钩子监视鼠标移动
来源:互联网 发布:angularjs数据格式化 编辑:程序博客网 时间:2024/06/04 19:58
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
...{
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
...{
Win32Hook hook = new Win32Hook();
hook.onMouseChange += new EventHandler(hook_onMouseChange);
hook.SetHook();
}
void hook_onMouseChange(object sender, EventArgs e)
...{
this.Text = Cursor.Position.ToString();
}
}
public class Win32Hook
...{
[DllImport("kernel32")]
public static extern int GetCurrentThreadId();
[DllImport("user32",CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int SetWindowsHookEx(
HookType idHook,
HOOKPROC lpfn,
int hmod,
int dwThreadId);
public enum HookType
...{
WH_GETMESSAGE = 3
}
public delegate int HOOKPROC(int nCode, int wParam, int lParam);
public event System.EventHandler onMouseChange;
public void SetHook()
...{
SetWindowsHookEx(HookType.WH_GETMESSAGE,
new HOOKPROC(this.MyKeyboardProc),
0,
GetCurrentThreadId());
}
public int MyKeyboardProc(int nCode, int wParam, int lParam)
...{
if (onMouseChange != null)
...{
onMouseChange(null, null);
}
return 0;
}
}
}
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
...{
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
...{
Win32Hook hook = new Win32Hook();
hook.onMouseChange += new EventHandler(hook_onMouseChange);
hook.SetHook();
}
void hook_onMouseChange(object sender, EventArgs e)
...{
this.Text = Cursor.Position.ToString();
}
}
public class Win32Hook
...{
[DllImport("kernel32")]
public static extern int GetCurrentThreadId();
[DllImport("user32",CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int SetWindowsHookEx(
HookType idHook,
HOOKPROC lpfn,
int hmod,
int dwThreadId);
public enum HookType
...{
WH_GETMESSAGE = 3
}
public delegate int HOOKPROC(int nCode, int wParam, int lParam);
public event System.EventHandler onMouseChange;
public void SetHook()
...{
SetWindowsHookEx(HookType.WH_GETMESSAGE,
new HOOKPROC(this.MyKeyboardProc),
0,
GetCurrentThreadId());
}
public int MyKeyboardProc(int nCode, int wParam, int lParam)
...{
if (onMouseChange != null)
...{
onMouseChange(null, null);
}
return 0;
}
}
}
- c#中通过设置钩子监视鼠标移动
- c#中通过设置钩子监视鼠标移动
- C#中通过设置钩子监视鼠标移动
- c#中通过设置钩子监视鼠标移动
- C#中通过设置钩子监视鼠标移动
- c#中通过设置钩子监视鼠标移动
- C#中通过设置钩子监视鼠标移动
- c#中通过设置钩子监视鼠标移动
- 使用C#钩子监视全局鼠标位置
- [Winform]通过钩子监控键盘操作和鼠标移动
- 【转】C#鼠标钩子
- C#鼠标键盘钩子
- C#全局鼠标钩子
- C# 鼠标钩子使用
- C#使用鼠标钩子
- C# 鼠标全局钩子
- C#键盘鼠标钩子
- C#鼠标钩子(转)
- 直方图均衡
- C#实现更改IP功能源代码
- "在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的"错误的原因和处理
- jsp如何获取客户端的mac地址
- 如何将加密的(web.config)文件部署到其他服务器上
- c#中通过设置钩子监视鼠标移动
- 将图像的像素数据保存到文本文件
- 位图的直方图均衡化和直方图的绘制
- 技术解析:什么是模式? 什么是框架?
- (转)解决 amule 启动后,kad状态一直为“firewalled”的状态,以及怎样增加kad连接数
- 如何通过在 Visual C++ 中单元封送接口
- 2008.12.29
- PUMA560机器人仿真系统
- 2008.12.31