MouseKeyHook.InjectedEvents 5.8.0

dotnet add package MouseKeyHook.InjectedEvents --version 5.8.0
NuGet\Install-Package MouseKeyHook.InjectedEvents -Version 5.8.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MouseKeyHook.InjectedEvents" Version="5.8.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MouseKeyHook.InjectedEvents --version 5.8.0
#r "nuget: MouseKeyHook.InjectedEvents, 5.8.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MouseKeyHook.InjectedEvents as a Cake Addin
#addin nuget:?package=MouseKeyHook.InjectedEvents&version=5.8.0

// Install MouseKeyHook.InjectedEvents as a Cake Tool
#tool nuget:?package=MouseKeyHook.InjectedEvents&version=5.8.0

nuget master

Mouse and Keyboard Hooking Library in c#

NEWS!

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

What it does?

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

Prerequisites

  • Windows: .NET Framework 4.0+

Installation and sources

<pre> nuget install MouseKeyHook </pre>

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 does it work?

This library attaches to windows global hooks, tracks keyboard and mouse clicks, movements 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 questions? 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
vNext vNext vNext

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

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net7.0-windows7.0 is compatible.  net8.0-windows was computed.  net8.0-windows7.0 is compatible. 
.NET Framework net472 is compatible.  net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • net6.0-windows7.0

    • No dependencies.
  • net7.0-windows7.0

    • No dependencies.
  • net8.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.8.0 173 1/9/2024