C#中处理全局鼠标及键盘勾子
作者:作者不详  发布日期:2011/06/16 22:17:35
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




本文来源:
点击下载附件 点击下载附件 (如下载失败,请邮件通知我们寄回给您,或QQ:23404761留言.)
上一篇 下一篇