globalmousekeyhook

This library allows you to tap keyboard and mouse, detect and record their activity even when an application is inactive and runs in background.

  • 所有者: gmamaladze/globalmousekeyhook
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

nuget master

Mouse and Keyboard Hooking Library in c#

NEWS!

Added support for detection of key combinations and sequences see: Quickstart - Detecting Key Combinations and Seuqnces

What it does?

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.

Prerequisites

  • Windows: .Net 4.0+

Installation and sources

Usage

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)

How it works?

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:

  • Mouse coordinates
  • Mouse buttons clicked
  • Mouse drag actions
  • Mouse wheel scrolls
  • Key presses and releases
  • Special key states

Additionally, there are MouseEventExtArgs and KeyEventExtArgs which provide further options:

  • Input suppression
  • Timestamp
  • IsMouseDown/Up
  • IsKeyDown/Up.

Troubleshooting and support

  • Usage or programming related question? Post it on StackOverflow using the tag mousekeyhook
  • Found a bug or missing a feature? Feed the issue tracker

Current project build status

The CI builds are generously hosted and run on the Travis and AppVeyor infrastructures., Travis-CI, AppVeyor, :---------, :-------------------------------------------------:, :-------------------------------------------------------:, master, [![master][master-travis-badge]][master-travis-url], master, vNext, vNext, vNext, [master-travis-url]: https://travis-ci.org/gmamaladze/globalmousekeyhook/branches/
[master-travis-badge]: https://travis-ci.org/gmamaladze/globalmousekeyhook.svg?branch=master

History, 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

Quick contributing guide

  • Fork and clone locally
  • Create a topic specific branch. Add some nice feature.
  • Send a Pull Request to spread the fun!

License

The MIT license see: LICENSE.txt

主要指标

概览
名称与所有者gmamaladze/globalmousekeyhook
主编程语言C#
编程语言C# (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2015-03-04 17:00:00
推送于2023-12-15 14:33:07
最后一次提交2023-04-10 12:21:13
发布数1
最新版本名称v5.4 (发布于 )
第一版名称v5.4 (发布于 )
用户参与
星数1.1k
关注者数73
派生数260
提交数287
已启用问题?
问题数136
打开的问题数93
拉请求数47
打开的拉请求数2
关闭的拉请求数12
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?