MouseHook 1.0.6

dotnet add package MouseHook --version 1.0.6
                    
NuGet\Install-Package MouseHook -Version 1.0.6
                    
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="MouseHook" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MouseHook" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="MouseHook" />
                    
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 MouseHook --version 1.0.6
                    
#r "nuget: MouseHook, 1.0.6"
                    
#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 MouseHook@1.0.6
                    
#: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=MouseHook&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=MouseHook&version=1.0.6
                    
Install as a Cake Tool

For 4.8 Use Release x64 /!\

GlobalMouseHook

Author: FauZaPespi
Date: 13.11.2024

Tired of having to rehook for each project? Use this already pre-made hook to call events at the right time, everything is perfect, use us


Description

A .NET library designed to globally hook mouse events, providing real-time monitoring and simulation of mouse actions. This library enables developers to intercept, track, and simulate mouse clicks programmatically.

Github repo

Discord profile


Features

  • Global Mouse Hooking:

    • Tracks mouse button events globally across the system.
    • Monitors cursor position during mouse events.
  • Mouse Button State Tracking:

    • Detects and stores the state of the left and right mouse buttons (IsKeepingLeftDown, IsKeepingRightDown).
  • Mouse Click Simulation:

    • Simulate left and right mouse button presses and releases (SendLeftDown, SendLeftUp, SendRightDown, SendRightUp).
  • Customizable Event Handling:

    • Raises a GlobalMouseClick event when a mouse button is pressed or released, with details of the button and cursor position.

Getting Started

Prerequisites

  • .NET Framework or .NET Core compatible runtime.
  • Administrative privileges to hook global system events.

Installation

Clone or download the repository and include the GlobalMouseHook class in your project.


Usage

1. Set Up Global Mouse Hook

Instantiate the GlobalMouseHook class to start monitoring mouse events globally.

var mouseHook = new GlobalMouseHook();
mouseHook.GlobalMouseClick += (button, position) =>
{
    Console.WriteLine($"Button: {button}, Position: {position}");
};

2. Check Mouse Button States

Use these methods to check the current state of the mouse buttons:


bool isLeftButtonPressed = mouseHook.IsLeftDown();
bool isRightButtonPressed = mouseHook.IsRightDown();

bool isLeftHeld = mouseHook.IsKeepingLeftDown();
bool isRightHeld = mouseHook.IsKeepingRightDown();

3. Simulate Mouse Actions

Simulate mouse clicks programmatically:

mouseHook.SendLeftDown();
mouseHook.SendLeftUp();

mouseHook.SendRightDown();
mouseHook.SendRightUp();

4. Clean Up Resources

Unhook the mouse hook when it is no longer needed:

mouseHook.Unhook();

Functionality

Functionality Description
SetHook() Sets up a global mouse hook using SetWindowsHookEx.
Unhook() Releases the global mouse hook using UnhookWindowsHookEx.
HookCallback() Processes mouse events and raises the GlobalMouseClick event.
GlobalMouseClick (event) Raised when a mouse button is pressed or released, providing button name and cursor position.
IsLeftDown() Checks if the left mouse button is currently pressed.
IsRightDown() Checks if the right mouse button is currently pressed.
IsKeepingLeftDown() Checks if the left mouse button is being held down.
IsKeepingRightDown() Checks if the right mouse button is being held down.
SendLeftDown() Simulates a left mouse button press.
SendLeftUp() Simulates a left mouse button release.
SendRightDown() Simulates a right mouse button press.
SendRightUp() Simulates a right mouse button release.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.6 143 11/15/2024

Changing some package stuff but not the class content you know ?