EventHook 2.0.0-beta

This is a prerelease version of EventHook.
dotnet add package EventHook --version 2.0.0-beta
                    
NuGet\Install-Package EventHook -Version 2.0.0-beta
                    
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-beta" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EventHook" Version="2.0.0-beta" />
                    
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-beta
                    
#r "nuget: EventHook, 2.0.0-beta"
                    
#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-beta
                    
#: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-beta&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=EventHook&version=2.0.0-beta&prerelease
                    
Install as a Cake Tool

Windows User Action Hook (EventHook)

CI NuGet

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 dotnet tool run docfx metadata docfx.json and dotnet tool run docfx build docfx.json

Release branches

Branch NuGet Notes
develop (no publish) CI build + tests + DocFX
beta EventHook 2.0.0-beta Merge developbeta to publish prerelease
stable / tag v2.* EventHook 2.0.0 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
2.0.0-beta 29 8/31/2026
1.4.113 12,932 11/10/2020
1.4.110 938 10/18/2020
1.4.105 21,836 11/21/2018
1.4.79 2,280 4/24/2018
1.4.74 2,079 4/13/2018
1.4.72 2,019 4/13/2018
1.4.70 2,062 4/13/2018
1.4.67 1,997 4/13/2018
1.4.64 2,025 4/13/2018
1.4.62 1,953 4/13/2018
1.4.59 1,910 4/13/2018
1.4.58 1,917 4/13/2018
1.4.39 3,932 6/17/2016
1.4.37 1,800 4/18/2016
1.4.34 1,905 4/6/2016
1.4.33 1,756 4/6/2016
1.4.32 1,824 4/6/2016
1.4.31 1,764 4/5/2016
1.4.30 1,770 4/5/2016
Loading failed