I've been researching for the past few hours to figure out how to detect mouse left clicks globally (not focused) and stumbled upon multiple posts mentioning to use globalmousekeyhook which I installed via NuGet which I have implemented as seen below:
using Gma.System.MouseKeyHook;
using System;
namespace mouse_hook_test
{
class Program
{
static private IKeyboardMouseEvents m_GlobalHook;
static void Main(string[] args)
{
Subscribe();
Console.ReadKey();
}
static public void Subscribe()
{
m_GlobalHook = Hook.GlobalEvents();
m_GlobalHook.MouseDownExt += GlobalHookMouseDownExt;
}
static private void GlobalHookMouseDownExt(object sender, MouseEventExtArgs e)
{
Console.WriteLine("Mouse Click.");
}
}
}
When I run it, my on screen mouse suddenly starts lagging to the point where it's unusable (I even struggled to close the command prompt) and I have also tried clicking both left and right but nothing get's logged. Am I doing something completely stupid? I feel there's something really obvious I'm missing because no one else is having this issue, or if there's another solution I'd be glad to try it. Thank you.
Visual Studio 2019, Windows 10 Pro, Project: .NET Framework 4.7.2, Console Application, ran with debug mode