Giter VIP home page Giter VIP logo

h.hooks's Introduction

Language License Requirements Build Status

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

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

h.hooks's People

Contributors

havendv avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.