KeyMouseHook是基於globalmousekeyhook 和 InputSimulator 的類似於按鍵精靈的模擬鍵盤按鍵和鼠標點擊操作的擴展類庫。
可以檢測並記錄鍵盤和鼠標的活動,你可以錄製你的鍵鼠操作的記錄並進行回放,可模擬鍵盤輸入和鼠標點擊操作。
git地址:https://gitee.com/loamen/KeyMouseHook
安裝環境Windows: .Net Framework 4.0+
安裝和源碼
nuget install KeyMouseHook
- https://www.nuget.org/packages/KeyMouseHook
- 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);
界面截圖
|