EventHook 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package EventHook --version 2.0.0
                    
NuGet\Install-Package EventHook -Version 2.0.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="EventHook" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EventHook" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="EventHook" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EventHook --version 2.0.0
                    
#r "nuget: EventHook, 2.0.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.
#:package EventHook@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EventHook&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=EventHook&version=2.0.0
                    
Install as a Cake Tool

Windows User Action Hook (EventHook)

CI NuGet

Code Quality

Quality Gate Coverage Lines of Code Bugs Vulnerabilities Code Smells Security Rating Reliability Rating Maintainability Rating Duplicated Lines Technical Debt

A .NET library to subscribe to Windows global user actions: keyboard, mouse, clipboard, application windows, print jobs, and hotkeys.

Requires: .NET 10 on Windows (net10.0-windows). AnyCPU — works on x86, x64, and ARM64 Windows when P/Invoke pointer sizes are correct (v2 fixes these).

Install

dotnet add package EventHook

Sample

using System;
using System.Windows.Forms;

using (var eventHookFactory = new EventHookFactory())
{
    var keyboardWatcher = eventHookFactory.GetKeyboardWatcher();
    keyboardWatcher.Start();
    keyboardWatcher.OnKeyInput += (s, e) =>
        Console.WriteLine($"Key {e.KeyData.EventType} of {e.KeyData.Keyname}");

    var mouseWatcher = eventHookFactory.GetMouseWatcher();
    mouseWatcher.IncludeMouseMove = false; // #28
    mouseWatcher.Start();
    mouseWatcher.OnMouseInput += (s, e) =>
        Console.WriteLine($"Mouse {e.Message} at {e.Point.x},{e.Point.y}");

    var clipboardWatcher = eventHookFactory.GetClipboardWatcher();
    clipboardWatcher.Start();
    clipboardWatcher.OnClipboardModified += (s, e) =>
        Console.WriteLine($"Clipboard {e.DataFormat}: {e.Data}");

    var applicationWatcher = eventHookFactory.GetApplicationWatcher();
    applicationWatcher.Start();
    applicationWatcher.OnApplicationWindowChange += (s, e) =>
        Console.WriteLine($"{e.ApplicationData.AppName} was {e.Event}");

    var printWatcher = eventHookFactory.GetPrintWatcher();
    printWatcher.Start();
    printWatcher.OnPrintEvent += (s, e) =>
        Console.WriteLine($"Printer {e.EventData.PrinterName} pages={e.EventData.Pages}");

    var hotkeyWatcher = eventHookFactory.GetHotkeyWatcher();
    hotkeyWatcher.Start();
    hotkeyWatcher.Register("demo", Keys.Control | Keys.Alt | Keys.H);
    hotkeyWatcher.OnHotkeyPressed += (s, e) =>
        Console.WriteLine($"Hotkey {e.Id} ({e.Keys})");

    Console.ReadLine();
}

Application window filter

EventHook.Helpers.AppWindowFilter.IncludeWindowsWithoutSysMenu = true; // games without WS_SYSMENU
EventHook.Helpers.AppWindowFilter.IncludeDialogs = true;               // MessageBox / #32770
EventHook.Helpers.AppWindowFilter.CustomFilter = hwnd => true;         // optional

Hosted apps (COM / Office add-ins)

Prefer constructing the factory on an STA UI thread, or pass an existing message-pump HWND:

using var factory = new EventHookFactory(hostMainWindowHandle);

VB.NET

See examples/EventHook.VB.Example. Context-menu paste is observed via the clipboard watcher (global); WM_PASTE itself is application-local.

PrintWatcher enumerates local and connected queues, including virtual printers such as Microsoft Print to PDF. Print a document to that queue to verify OnPrintEvent.

Development

  • Visual Studio 2022 / .NET 10 SDK
  • dotnet build src/EventHook.sln -c Release
  • dotnet test tests/EventHook.Tests
  • dotnet test tests/EventHook.IntegrationTests
  • Docs: dotnet tool restore then docfx .github/docfx.json (writes API HTML under docs/, same as titanium-web-proxy)

Release branches

Branch NuGet Notes
develop (no publish) CI build + tests + DocFX
beta {VersionPrefix}-beta from EventHook.csproj Merge developbeta to publish prerelease
stable / tag v* {VersionPrefix} from csproj Stable release + GitHub Pages docs

Publishing uses NuGet Trusted Publishing (NUGET_USER on the nuget-publish environment), same pattern as titanium-web-proxy.

Version 2.0 notes

Breaking: targets net10.0-windows only (no longer .NET Framework 4.5).

Highlights: HotkeyWatcher, mouse-move filter, clipboard images/files, dialog/MsgBox tracking, PDF/virtual printers, x64/ARM64 P/Invoke fixes, reliable Stop/Dispose, GitHub Actions CI + DocFX.

Product Compatible and additional computed target framework versions.
.NET net10.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on EventHook:

Repository Stars
mann1x/CPUDoc
Version Downloads Last Updated
3.0.0 74 9/8/2026
3.0.0-beta.2 48 9/8/2026
3.0.0-beta 71 9/8/2026
2.0.0 86 9/7/2026
2.0.0-beta 87 8/31/2026
1.4.113 12,961 11/10/2020
1.4.110 948 10/18/2020
1.4.105 21,848 11/21/2018
1.4.79 2,290 4/24/2018
1.4.74 2,091 4/13/2018
1.4.72 2,031 4/13/2018
1.4.70 2,073 4/13/2018
1.4.67 2,010 4/13/2018
1.4.64 2,036 4/13/2018
1.4.62 1,968 4/13/2018
1.4.59 1,922 4/13/2018
1.4.58 1,931 4/13/2018
1.4.39 3,949 6/17/2016
1.4.37 1,812 4/18/2016
1.4.34 1,917 4/6/2016
Loading failed