这是一个基于globalmousekeyhook 和 InputSimulator 的类似于按键精灵的模拟键盘按键和鼠标点击操作的扩展类库。可以检测并记录键盘和鼠标的活动,你可以录制你的键鼠操作的记录并进行回放,可模拟键盘输入和鼠标点击操作。
nuget install KeyMouseHook
NuGet package
Source code(github)
Source code(码云)
private readonly KeyMouseFactory eventHookFactory = new KeyMouseFactory(HookType.GlobalEvents); private readonly KeyboardWatcher keyboardWatcher; private readonly MouseWatcher mouseWatcher; private List _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(); keyboardWatcher.Start(events); mouseWatcher.Start(events); } private void StopWatch() { keyboardWatcher.Stop(); mouseWatcher.Stop(); } private void Playback() { var sim = new InputSimulator(); //var sim = new KeyMouseSimulator(); sim.PlayBack(_macroEvents); }
(源码里包含更详细的示例)
globalmousekeyhook (MIT License)
InputSimulator (MIT License)
Fork并克隆到本机
创建一个分支并添加你的代码
发送一个Pull Request
The MIT license see: LICENSE