C# monitor keyboard and mouse actions based on MouseKeyHook.
程序员文章站
2022-04-10 13:49:31
1.Install-package MouseKeyHook 2. using Gma.System.MouseKeyHook; using System; namespace ConsoleApp1 { public class MonitorHelper { public static void ......
1.install-package mousekeyhook
2.
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.
static void main(string[] args) { mousemonitor(); console.readline(); } static void mousemonitor() { monitorhelper.listenformouseevents(); application.run(new applicationcontext()); }