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).
- API Documentation (generated DocFX site on
develop)
dotnet add package EventHookusing 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();
}EventHook.Helpers.AppWindowFilter.IncludeWindowsWithoutSysMenu = true; // games without WS_SYSMENU
EventHook.Helpers.AppWindowFilter.IncludeDialogs = true; // MessageBox / #32770
EventHook.Helpers.AppWindowFilter.CustomFilter = hwnd => true; // optionalPrefer constructing the factory on an STA UI thread, or pass an existing message-pump HWND:
using var factory = new EventHookFactory(hostMainWindowHandle);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.
- Visual Studio 2022 / .NET 10 SDK
dotnet build src/EventHook.sln -c Releasedotnet test tests/EventHook.Testsdotnet test tests/EventHook.IntegrationTests- Docs:
dotnet tool restorethendocfx .github/docfx.json(writes API HTML underdocs/, same as titanium-web-proxy)
| Branch | NuGet | Notes |
|---|---|---|
develop |
(no publish) | CI build + tests + DocFX |
beta |
{VersionPrefix}-beta from EventHook.csproj |
Merge develop → beta 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.
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.