C#中处理全局鼠标及键盘勾子
Processing Global Mouse and Keyboard Hooks in C#
Introduction
This class allows you to tap keyboard and mouse and/or to detect their activity even when an application runs in the background or does not have any user interface at all. This class raises common .NET events with KeyEventArgs and MouseEventArgs, so you can easily retrieve any information you need.
CSFramework.com翻译
C#中处理全局鼠标及键盘勾子
这个类允许你监控在后台运行或没有任何用户界面的程序中的鼠标和键盘活动,引发.NET中通用的KeyEventArgs和MouseEventArgs事件,所以你可以轻松地获取您需要的任何信息。
UserActivityHook actHook;
void MainFormLoad(object sender, System.EventArgs e)
{
actHook = new UserActivityHook(); // crate an instance
// hang on events
actHook.OnMouseActivity += new MouseEventHandler(MouseMoved);
actHook.KeyDown += new KeyEventHandler(MyKeyDown);
actHook.KeyPress += new KeyPressEventHandler(MyKeyPress);
actHook.KeyUp += new KeyEventHandler(MyKeyUp);
}
public void MouseMoved(object sender, MouseEventArgs e)
{
labelMousePosition.Text = String.Format("x={0} y={1}", e.X, e.Y);
if (e.Clicks > 0) LogWrite("MouseButton - " + e.Button.ToString());
}
原文转自codeproject:
http://www.codeproject.com/KB/cs/globalhook.aspx
本文来源: