鼠标和键盘操作的全局钩子(较好)

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

using System;

using ponentModel;

using System.Reflection;

using System.Runtime.InteropServices;

using System.Windows.Forms;

namespace UserActivityMonitor

{

///

///This class monitors all mouse activities globally (also outside of the application)

///and provides appropriate events.

///

public static class HookManager

{

///

///Occurs when the mouse pointer is moved.

///

public static event MouseEventHandler MouseMove

{

add

{

EnsureSubscribedToGlobalMouseEvents();

s_MouseMove += value;

}

remove

{

s_MouseMove -= value;

TryUnsubscribeFromGlobalMouseEvents();

}

}

///

///Occurs when a click was performed by the mouse.

///

public static event MouseEventHandler MouseClick

{

add

{

EnsureSubscribedToGlobalMouseEvents();

s_MouseClick += value;

}

remove

{

s_MouseClick -= value;

TryUnsubscribeFromGlobalMouseEvents();

}

}

///

///Occurs when the mouse a mouse button is pressed.

///

public static event MouseEventHandler MouseDown

{

add

{

EnsureSubscribedToGlobalMouseEvents();

s_MouseDown += value;

}

remove

{

s_MouseDown -= value;

TryUnsubscribeFromGlobalMouseEvents();

}

}

///

///Occurs when a mouse button is released.

///

public static event MouseEventHandler MouseUp

{

add

{

EnsureSubscribedToGlobalMouseEvents();

s_MouseUp += value;

}

remove

{

s_MouseUp -= value;

TryUnsubscribeFromGlobalMouseEvents();

}

}

///

///Occurs when the mouse wheel moves.

///

public static event MouseEventHandler MouseWheel {

add

{

EnsureSubscribedToGlobalMouseEvents();

s_MouseWheel += value;

}

remove

{

s_MouseWheel -= value;

TryUnsubscribeFromGlobalMouseEvents();

}

}

///

///Occurs when a double clicked was performed by the mouse.

///

public static event MouseEventHandler MouseDoubleClick

{

add

{

EnsureSubscribedToGlobalMouseEvents();

if (s_MouseDoubleClick == null)

{

s_DoubleClickTimer = new Timer

{

Interval = GetDoubleClickTime(),

Enabled = false };

s_DoubleClickTimer.Tick += DoubleClickTimeElapsed; MouseUp += OnMouseUp;

}

s_MouseDoubleClick += value;

}

remove

{

if (s_MouseDoubleClick != null)

{

s_MouseDoubleClick -= value;

相关文档
最新文档