1.Install-package MouseKeyHookspa
2.code
using Gma.System.MouseKeyHook; using System; namespace ConsoleApp1 { public class MonitorHelper { public static void ListenForMouseEvents() { Hook.GlobalEvents().MouseClick += (sender, e) => { Console.WriteLine($"{DateTime.Now.ToString("yyyyMMddHHmmssffff")} Mouse {e.Button} clicked."); }; Hook.GlobalEvents().MouseDoubleClick += (sender, e) => { Console.WriteLine($"{DateTime.Now.ToString("yyyyMMddHHmmssffff")} Mouse {e.Button} button double clicked."); }; Hook.GlobalEvents().MouseDragFinished += (sender, e) => { Console.WriteLine($"{DateTime.Now.ToString("yyyyMMddHHmmssffff")} Mouse {e.Button} dragged"); }; Hook.GlobalEvents().MouseWheel += (sender, e) => { Console.WriteLine($"{DateTime.Now.ToString("yyyyMMddHHmmssffff")} Mouse scrolls"); }; Hook.GlobalEvents().KeyDown += (sender, e) => { Console.WriteLine($"{DateTime.Now.ToString("yyyyMMddHHmmssffff")} pressed {e.KeyCode}"); }; } } }
3.blog
static void Main(string[] args) { MouseMonitor(); Console.ReadLine(); } static void MouseMonitor() { MonitorHelper.ListenForMouseEvents(); Application.Run(new ApplicationContext()); }