1 Star 0 Fork 48

四个石头 / KeyMouseHook

forked from loamen / KeyMouseHook 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 3.99 KB
一键复制 编辑 原始数据 按行查看 历史
玏佾 提交于 2018-12-04 16:21 . update win api

nuget stable build license platforms download_count release

Keyboard and Mouse Hooking and Simulator Library in c#(winform)

中文介绍

What it does?

This is an extension to globalmousekeyhook and InputSimulator library which allows you to tap keyboard and mouse, to detect and record their activity event when an application is inactive and runs in background.The Windows Input Simulator provides a simple .NET(C#) interface to simulate Keyboard or Mouse input using the Win32 SendInput method.

Prerequisites

  • Windows: .Net Framework 4.0+

Installation and sources

nuget install KeyMouseHook

Usage

private readonly KeyMouseFactory eventHookFactory = new KeyMouseFactory(HookType.GlobalEvents);
private readonly KeyboardWatcher keyboardWatcher;
private readonly MouseWatcher mouseWatcher;
private List<MouseKeyEvent> _mouseKeyEvents;

public FormMain()
{
   InitializeComponent();

   keyboardWatcher = eventHookFactory.GetKeyboardWatcher();
   keyboardWatcher.OnKeyboardInput += (s, e) =>
   {
	if (_mouseKeyEvents != null)
	    _mouseKeyEvents.Add(e);
   };

   mouseWatcher = eventHookFactory.GetMouseWatcher();
   mouseWatcher.OnMouseInput += (s, e) =>
   {
	if (_mouseKeyEvents != null)
	    _mouseKeyEvents.Add(e);
   };
}

private void StartWatch(IKeyboardMouseEvents events = null)
{
    _macroEvents = new List<MacroEvent>();
    keyboardWatcher.Start(events);
    mouseWatcher.Start(events);
}

private void StopWatch()
{
   keyboardWatcher.Stop();
   mouseWatcher.Stop();
}

private void Playback()
{
   var sim = new InputSimulator();
   sim.PlayBack(_macroEvents);
}
keyboardWatcher = eventHookFactory.GetKeyboardWatcher().Disable(MacroEventType.KeyDown | MacroEventType.KeyUp).Enable(MacroEventType.KeyPress);
mouseWatcher = eventHookFactory.GetMouseWatcher().Enable(MacroEventType.MouseDoubleClick | MacroEventType.MouseDragStarted).Disable(MacroEventType.MouseDragFinished | MacroEventType.MouseMove);
var sim = new InputSimulator().Enable(MacroEventType.MouseDoubleClick | MacroEventType.KeyPress).Disable(MacroEventType.MouseMove | MacroEventType.KeyDown | MacroEventType.KeyUp);

(also have a look at the Demo app included with the source)

Screen Shots

Keyboard and Mouse Hooking and Simulator Library in c#(winform)

Thanks

Quick contributing guide

  • Fork and clone locally
  • Create a topic specific branch. Add some nice feature.
  • Send a Pull Request!

License

The MIT license see: LICENSE

C#
1
https://gitee.com/sigeshitou1987/KeyMouseHook.git
git@gitee.com:sigeshitou1987/KeyMouseHook.git
sigeshitou1987
KeyMouseHook
KeyMouseHook
master

搜索帮助