H.Hooks 1.4.19
H.Hooks
It uses Win32 kernel32.dll and user32.dll calls inside.
Contains LowLevelKeyboardHook and LowLevelMouseHook.
Features:
- Global key handling and cancellation
- Allows handling combination like 1 + 2 + 3
- Only one Up event per combination
- Handle special buttons like Mouse.XButton
- Optimized, runs hooks in a separate thread. Does not cause freezes when debugging the rest of the code.
- By default, it delivers events from a ThreadPool instead of a hook thread, which makes it possible to do any action in event handlers without affecting system performance.
Nuget
Install-Package H.Hooks
Usage
using var keyboardHook = new LowLevelKeyboardHook();
keyboardHook.Up += (_, args) => Console.WriteLine($"{nameof(keyboardHook.Up)}: {args}");
keyboardHook.Down += (_, args) => Console.WriteLine($"{nameof(keyboardHook.Down)}: {args}");
keyboardHook.Start();
using var mouseHook = new LowLevelMouseHook();
mouseHook.Down += (_, args) => Console.WriteLine($"{nameof(mouseHook.Down)}: {args}");
mouseHook.Move += (_, args) => Console.WriteLine($"{nameof(mouseHook.Move)}: {args}");
mouseHook.Start();
// Check keys
if (args.Keys.Are(Key.Control, Key.Escape)) {
// Exit?
}
Interception of input and cancellation
Allows you to intercept input for other applications and cancel events (via args.IsHandled = true).
Do not enable this unless you need it.
When enabled, overrides the automatic dispatch of events to the ThreadPool
and may cause performance issues with any slow handlers. In this case,
you need to use ThreadPool.QueueUserWorkItem(WaitCallback)
when handling events (after set up args.IsHandled = true).
hook.Handling = true;
hook.Up += (_, args) => args.IsHandled = true;
Advanced usage
// Enables Move events.
mouseHook.GenerateMouseMoveEvents = true;
// Adds keyboard keys. Allows getting combinations like Shift + LeftMouse.
mouseHook.AddKeyboardKeys = true;
// Sends multiple events while key pressed.
keyboardHook.OneUpEvent = false;
// Allows handle modifier keys.
keyboardHook.HandleModifierKeys = true;
// Allows common key combinations, like 1 + 2 + 3.
hook.IsExtendedMode = true;
// Events will contains separate Left/Right keys.
hook.IsLeftRightGranularity = true;
// Uses User32.GetKeyboardState instead User32.GetKeyState.
// Disable this if any problem.
hook.UseKeyboardState = false;
// Adds Key.Caps to each event if CapsLock is toggled.
hook.IsCapsLock = false;
Contacts
Showing the top 20 packages that depend on H.Hooks.
| Packages | Downloads |
|---|---|
|
Lib.KeyboardEvent
Package Description
|
12 |
|
Lib.KeyboardEvent
Package Description
|
10 |
|
Lib.KeyboardEvent
Package Description
|
1 |
⭐ Last 10 features:
- feat: Added KeyboardEventArgs.CurrentKey property. 2022-03-17
- feat: Added net5/net6 targets. 2022-03-17
- fix: Fixed preview features. 2022-02-15
- feat: Added Keys.Are method. 2022-02-15
- feat: Changed minimal requirement to net4.5.1. 2022-02-15
- feat: Updated README. 2021-10-21
- feat: to net6.0 and C# 10. 2021-10-21
- feat: Updated package description. 2021-06-14
- feat: Added auto-releasing. 2021-06-13
- feat: Added PackageReadmeFile. 2021-06-13
🐞 Last 10 bug fixes:
- fix: Fixed #2 issue. 2022-02-15
- fix: Fixed preview features. 2022-02-15
- fix: Added Keys == and != operators. 2022-02-15
- fix: Fixed ci os. 2021-10-21
- fix: Fixed PackageReadmeFile. 2021-10-21
- fix: Fixed ConsoleApp. 2021-10-21
- fix: Deleted unused code. 2021-07-10
- fix: Fixed PackageReadmeFile bug. 2021-06-13
- fix: Fixed mouse double click bug. 2021-01-22
- fix: Fixed Hook Windows messages filter bug. 2021-01-21
.NET Framework 4.5.1
- No dependencies.
.NET 5.0
- Microsoft.Win32.Registry (>= 5.0.0)
.NET 6.0
- Microsoft.Win32.Registry (>= 5.0.0)
.NET Standard 2.0
- Microsoft.Win32.Registry (>= 5.0.0)
| Version | Downloads | Last updated |
|---|---|---|
| 1.7.0 | 13 | 02/19/2025 |
| 1.6.0 | 12 | 02/19/2025 |
| 1.4.21 | 12 | 02/19/2025 |
| 1.4.20 | 12 | 02/19/2025 |
| 1.4.19 | 12 | 02/19/2025 |
| 1.4.18 | 10 | 02/19/2025 |
| 1.4.17 | 10 | 02/19/2025 |
| 1.4.14 | 11 | 02/19/2025 |
| 1.4.13 | 10 | 02/19/2025 |
| 1.4.12 | 10 | 02/19/2025 |
| 1.4.9 | 10 | 02/19/2025 |
| 1.4.8 | 10 | 02/19/2025 |
| 1.4.7 | 10 | 02/19/2025 |
| 1.4.6 | 10 | 02/19/2025 |
| 1.4.5 | 10 | 02/19/2025 |
| 1.4.3 | 10 | 02/19/2025 |
| 1.3.2 | 10 | 02/19/2025 |
| 1.3.1 | 10 | 02/19/2025 |
| 1.3.0 | 10 | 02/19/2025 |
| 1.2.4 | 10 | 02/19/2025 |
| 1.2.3 | 10 | 02/19/2025 |
| 1.2.2 | 10 | 02/19/2025 |
| 1.2.1 | 10 | 02/19/2025 |
| 1.2.0 | 11 | 02/19/2025 |
| 1.1.0 | 10 | 02/19/2025 |
| 1.0.1 | 11 | 02/19/2025 |
| 1.0.0 | 10 | 02/19/2025 |