UI设计 薇晓朵数字商城

 找回密碼
 加入我們

[精品源碼] 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);


界面截圖

回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 加入我們

本版積分規則

备案权重域名预定

4um點擊跨境網編創業社區

GMT+8, 2024-11-24 03:22

By DZ X3.5

QQ

快速回復 返回頂部 返回列表