[精品源码] KeyMouseHook类按键精灵的模拟键盘按键和鼠标点击操作的扩展类库

[复制链接]
小猪哼囔 发表于 2019-2-6 17:47:05 | 显示全部楼层 |阅读模式
KeyMouseHook是基于globalmousekeyhook 和 InputSimulator 的类似于按键精灵的模拟键盘按键和鼠标点击操作的扩展类库。

可以检测并记录键盘和鼠标的活动,你可以录制你的键鼠操作的记录并进行回放,可模拟键盘输入和鼠标点击操作。

git地址:https://gitee.com/loamen/KeyMouseHook

安装环境Windows: .Net Framework 4.0+

安装和源码

nuget install KeyMouseHook
  1. https://www.nuget.org/packages/KeyMouseHook
  2. https://github.com/loamen/KeyMouseHook
复制代码


使用

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();
   //var sim = new KeyMouseSimulator();
   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);


界面截图

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入我们

本版积分规则 返回列表 发新帖

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

快速回复 返回顶部 返回列表