Added support for detection of key combinations and sequences see.: Quickstart - Detecting Key Combinations and Seuqnces
This library allows you to tap keyboard and mouse, to detect and record their activity even when an application is inactive and runs in background.
nuget install MouseKeyHook
private IKeyboardMouseEvents m_GlobalHook;
public void Subscribe()
{
// Note: for the application hook, use the Hook.AppEvents() instead
m_GlobalHook = Hook.GlobalEvents();
m_GlobalHook.MouseDownExt += GlobalHookMouseDownExt;
m_GlobalHook.KeyPress += GlobalHookKeyPress;
}
private void GlobalHookKeyPress(object sender, KeyPressEventArgs e)
{
Console.WriteLine("KeyPress: \t{0}", e.KeyChar);
}
private void GlobalHookMouseDownExt(object sender, MouseEventExtArgs e)
{
Console.WriteLine("MouseDown: \t{0}; \t System Timestamp: \t{1}", e.Button, e.Timestamp);
// uncommenting the following line will suppress the middle mouse button click
// if (e.Buttons == MouseButtons.Middle) { e.Handled = true; }
}
public void Unsubscribe()
{
m_GlobalHook.MouseDownExt -= GlobalHookMouseDownExt;
m_GlobalHook.KeyPress -= GlobalHookKeyPress;
//It is recommened to dispose it
m_GlobalHook.Dispose();
}
(also have a look at the Demo app included with the source)
This library attaches to windows global hooks, tracks keyboard and mouse clicks and movement and raises common .NET events with KeyEventArgs and MouseEventArgs, so you can easily retrieve any information you need:
Additionally, there are MouseEventExtArgs
and KeyEventExtArgs
which provide further options:
The CI builds are generously hosted and run on the Travis and AppVeyor infrastructures.
Travis-CI | AppVeyor | |
---|---|---|
master | ||
vNext |
Year | URL |
---|---|
2000 - 2008 | http://www.codeproject.com/KB/cs/globalhook.aspx |
2008 - 2015 | https://globalmousekeyhook.codeplex.com/ |
2015 - now | https://github.com/gmamaladze/globalmousekeyhook |
The MIT license (Refer to the LICENSE.md file)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。