static void Main(string[] args) { var eventHookFactory = new EventHookFactory(); // 用工厂方法获得watcher对象 var keyboardWatcher = eventHookFactory.GetKeyboardWatcher(); // 启动钩子 keyboardWatcher.Start(); // 添加按键信息的回调方法 keyboardWatcher.OnKeyInput += (s, e) => { Console.WriteLine("Key {0} event of key {1}", e.KeyData.EventType, e.KeyData.Keyname); }; var mouseWatcher = eventHookFactory.GetMouseWatcher(); mouseWatcher.Start(); mouseWatcher.OnMouseInput += (s, e) => { Console.WriteLine("Mouse event {0} at point {1},{2}", e.Message.ToString(), e.Point.x, e.Point.y); }; Console.Read(); keyboardWatcher.Stop(); mouseWatcher.Stop(); eventHookFactory.Dispose(); }
public EventHookRecorder() { var eventHookFactory = new EventHookFactory(); mouseWatcher = eventHookFactory.GetMouseWatcher(); keyboardWatcher = eventHookFactory.GetKeyboardWatcher(); }
internal static void Start() { if (started) { return; } mouseWatcher = eventHookFactory.GetMouseWatcher(); mouseWatcher.Start(); mouseWatcher.OnMouseInput += (s, e) => { // 根据官网文档中定义,lParam低16位存储鼠标的x坐标,高16位存储y坐标 int lParam = e.Point.y; lParam <<= 16; lParam |= e.Point.x; // 发送消息给目标窗口 foreach (var window in HTargetWindows) { PostMessageW(window, (uint)e.Message, (IntPtr)0x0020, (IntPtr)lParam); } Console.WriteLine("Mouse event {0} at point {1},{2}", e.Message.ToString(), e.Point.x, e.Point.y); }; started = true; }
private static void Main(string[] args) { var eventHookFactory = new EventHookFactory(); var keyboardWatcher = eventHookFactory.GetKeyboardWatcher(); keyboardWatcher.Start(); keyboardWatcher.OnKeyInput += (s, e) => { Console.WriteLine("Key {0} event of key {1}", e.KeyData.EventType, e.KeyData.Keyname); }; var mouseWatcher = eventHookFactory.GetMouseWatcher(); mouseWatcher.Start(); mouseWatcher.OnMouseInput += (s, e) => { Console.WriteLine("Mouse event {0} at point {1},{2}", e.Message.ToString(), e.Point.x, e.Point.y); }; var clipboardWatcher = eventHookFactory.GetClipboardWatcher(); clipboardWatcher.Start(); clipboardWatcher.OnClipboardModified += (s, e) => { Console.WriteLine("Clipboard updated with data '{0}' of format {1}", e.Data, e.DataFormat.ToString()); }; var applicationWatcher = eventHookFactory.GetApplicationWatcher(); applicationWatcher.Start(); applicationWatcher.OnApplicationWindowChange += (s, e) => { Console.WriteLine("Application window of '{0}' with the title '{1}' was {2}", e.ApplicationData.AppName, e.ApplicationData.AppTitle, e.Event); }; var printWatcher = eventHookFactory.GetPrintWatcher(); printWatcher.Start(); printWatcher.OnPrintEvent += (s, e) => { Console.WriteLine("Printer '{0}' currently printing {1} pages.", e.EventData.PrinterName, e.EventData.Pages); }; Console.Read(); keyboardWatcher.Stop(); mouseWatcher.Stop(); clipboardWatcher.Stop(); applicationWatcher.Stop(); printWatcher.Stop(); eventHookFactory.Dispose(); }
//Inicializando a janela principal da aplicação public MainWindow() { InitializeComponent(); System.Windows.Application.Current.Exit += OnApplicationExit; //Assim que o aplicativo começa a rodar, o mouseWatcher começa a receber os eventos do mouse mouseWatcher = eventHookFactory.GetMouseWatcher(); mouseWatcher.Start(); }
public MainWindow() { HotkeyManager.HotkeyAlreadyRegistered += HotkeyManager_HotkeyAlreadyRegistered; HotkeyManager.Current.AddOrReplace("Increment", IncrementGesture, OnIncrement); InitializeComponent(); tcp_client.reff = this; tcp_server.reff = this; Application.Current.Exit += OnApplicationExit; mouseWatcher = eventHookFactory.GetMouseWatcher(); mouseWatcher.Start(); mouseWatcher.OnMouseInput += (s, e) => { if (e.Message.ToString() == "WM_LBUTTONUP") { if (isHotkeyOn) { send("c$" + e.Point.x + "," + e.Point.y); } } }; //clipboardWatcher = eventHookFactory.GetClipboardWatcher(); //clipboardWatcher.Start(); //clipboardWatcher.OnClipboardModified += (s, e) => //{ // Console.WriteLine("Clipboard updated with data '{0}' of format {1}", e.Data, // e.DataFormat.ToString()); //}; //applicationWatcher = eventHookFactory.GetApplicationWatcher(); //applicationWatcher.Start(); //applicationWatcher.OnApplicationWindowChange += (s, e) => //{ // Console.WriteLine("Application window of '{0}' with the title '{1}' was {2}", // e.ApplicationData.AppName, e.ApplicationData.AppTitle, e.Event); //}; //printWatcher = eventHookFactory.GetPrintWatcher(); //printWatcher.Start(); //printWatcher.OnPrintEvent += (s, e) => //{ // Console.WriteLine("Printer '{0}' currently printing {1} pages.", e.EventData.PrinterName, // e.EventData.Pages); //}; eventHookFactory.Dispose(); }
public MainWindow() { InitializeComponent(); Application.Current.Exit += OnApplicationExit; keyboardWatcher = eventHookFactory.GetKeyboardWatcher(); keyboardWatcher.Start(); keyboardWatcher.OnKeyInput += (s, e) => { Console.WriteLine("Key {0} event of key {1}", e.KeyData.EventType, e.KeyData.Keyname); }; mouseWatcher = eventHookFactory.GetMouseWatcher(); mouseWatcher.Start(); mouseWatcher.OnMouseInput += (s, e) => { Console.WriteLine("Mouse event {0} at point {1},{2}", e.Message.ToString(), e.Point.x, e.Point.y); }; clipboardWatcher = eventHookFactory.GetClipboardWatcher(); clipboardWatcher.Start(); clipboardWatcher.OnClipboardModified += (s, e) => { Console.WriteLine("Clipboard updated with data '{0}' of format {1}", e.Data, e.DataFormat.ToString()); }; applicationWatcher = eventHookFactory.GetApplicationWatcher(); applicationWatcher.Start(); applicationWatcher.OnApplicationWindowChange += (s, e) => { Console.WriteLine("Application window of '{0}' with the title '{1}' was {2}", e.ApplicationData.AppName, e.ApplicationData.AppTitle, e.Event); }; printWatcher = eventHookFactory.GetPrintWatcher(); printWatcher.Start(); printWatcher.OnPrintEvent += (s, e) => { Console.WriteLine("Printer '{0}' currently printing {1} pages.", e.EventData.PrinterName, e.EventData.Pages); }; eventHookFactory.Dispose(); }
public MainWindow() { InitializeComponent(); if (Properties.Settings.Default["filePath"].ToString() != "") { filePath = Properties.Settings.Default["filePath"].ToString(); } else { filePath = Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), @"Videos\Observations"); } for (int i = 0; i < Screen.AllScreens.Length; i++) { ScreenBox.Items.Add("Display " + (i + 1)); } ScreenBox.SelectedIndex = currentScreen; ScreenBox.SelectionChanged += ScreenBox_SelectedIndexChanged; SelectLocationButton.Click += SelectLocationButton_Click; TrayRecordButton.Click += TrayRecordButton_Click; SettingsButton.Click += SettingsButton_Click; ClosingButton.Click += ClosingButton_Click; QuitButton.Click += QuitButton_Click; LocationEntry.Text = filePath; SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; Hide(); #region Configure Event Handlers keyboardWatcher = eventHookFactory.GetKeyboardWatcher(); keyboardWatcher.Start(); keyboardWatcher.OnKeyInput += (s, e) => { string eventString = string.Format("Key {0} event of key {1}", e.KeyData.EventType, e.KeyData.Keyname); Dispatcher.BeginInvoke((Action)(() => { KeyboardEvents.Content = eventString; })); if (isRecording) { eventWriter.WriteEvent(EventWriter.InputEvent.Keyboard, eventString); } }; mouseWatcher = eventHookFactory.GetMouseWatcher(); mouseWatcher.Start(); mouseWatcher.OnMouseInput += (s, e) => { string eventString = string.Format("Mouse event {0} at point {1},{2}", e.Message.ToString(), e.Point.x, e.Point.y); Dispatcher.BeginInvoke((Action)(() => { MouseEvents.Content = eventString; })); if (isRecording) { if (e.Message.ToString() == "WM_LBUTTONDOWN" || e.Message.ToString() == "WM_RBUTTONDOWN") { eventWriter.WriteEvent(EventWriter.InputEvent.MouseClick, eventString); } else { if ((mousePosition[0] == 0 && mousePosition[1] == 0) || Math.Abs(e.Point.x - mousePosition[0]) >= minDistance || Math.Abs(e.Point.y - mousePosition[1]) >= minDistance) { mousePosition[0] = e.Point.x; mousePosition[1] = e.Point.y; eventWriter.WriteEvent(EventWriter.InputEvent.MouseMove, eventString); } } } }; clipboardWatcher = eventHookFactory.GetClipboardWatcher(); clipboardWatcher.Start(); clipboardWatcher.OnClipboardModified += (s, e) => { eventWriter.WriteEvent(EventWriter.InputEvent.Clipboard, e.Data.ToString()); }; applicationWatcher = eventHookFactory.GetApplicationWatcher(); applicationWatcher.Start(); applicationWatcher.OnApplicationWindowChange += (s, e) => { string eventString = string.Format("Application window of '{0}' with the title '{1}' was {2}", e.ApplicationData.AppName, e.ApplicationData.AppTitle, e.Event); Dispatcher.Invoke(() => { ApplicationEvents.Content = eventString; }); if (isRecording) { eventWriter.WriteEvent(EventWriter.InputEvent.Application, eventString); } }; printWatcher = eventHookFactory.GetPrintWatcher(); printWatcher.Start(); printWatcher.OnPrintEvent += (s, e) => { string eventString = string.Format("Printer '{0}' currently printing {1} pages.", e.EventData.PrinterName, e.EventData.Pages); Dispatcher.Invoke(() => { PrinterEvents.Content = eventString; }); if (isRecording) { eventWriter.WriteEvent(EventWriter.InputEvent.Print, eventString); } }; #endregion try { RegisterChromeExtension(); } catch (Exception e) { NotifyIcon.ShowBalloonTip("Exception", e.Message, BalloonIcon.Info); } }
public MainForm() { Application.ApplicationExit += OnApplicationExit; InitializeComponent(); keyboardWatcher = eventHookFactory.GetKeyboardWatcher(); keyboardWatcher.OnKeyInput += (s, e) => { if (e.KeyData.EventType.ToString() == "down") { current_time = DateTime.Now; Hashtable this_event = new Hashtable { { "Event Type", "Keyboard" }, { "Event Info", e.KeyData.Keyname }, { "Job id", job_id }, { "Resource", resource }, { "Form", GainActivatedForm() }, { "Timestamp", current_time.ToString("yyyy-MM-dd HH:mm:ss") + "." + current_time.Millisecond.ToString() } }; eventlog.Add(this_event); } }; mouseWatcher = eventHookFactory.GetMouseWatcher(); string[] MouseMoveMent = { "WM_WHEELBUTTONDOWN", "WM_LBUTTONDOWN", "WM_MOUSEWHEEL", "WM_WHEELBUTTONDOWN" }; mouseWatcher.OnMouseInput += (s, e) => { if (Array.IndexOf(MouseMoveMent, e.Message.ToString()) != -1) { current_time = DateTime.Now; string[] inter = GainMouseClickClassName(e.Point.x, e.Point.y); Hashtable this_event = new Hashtable { { "Event Type", "Mouse" }, { "Event Info", e.Message.ToString() }, { "Position", e.Point.x.ToString() + "|" + e.Point.y.ToString() }, { "Job id", job_id }, { "Resource", resource }, { "Form", GainActivatedForm() }, { "Click_Name", inter[1] }, { "Click_ClassName", inter[0] }, { "Timestamp", current_time.ToString("yyyy-MM-dd HH:mm:ss") + "." + current_time.Millisecond.ToString() } }; eventlog.Add(this_event); } ; }; applicationWatcher = eventHookFactory.GetApplicationWatcher(); applicationWatcher.OnApplicationWindowChange += (s, e) => { Hashtable this_event = new Hashtable { { "Event Type", "Application" }, { "Event Info", e.ApplicationData.AppName + "|" + e.ApplicationData.AppTitle + "|" + e.Event }, { "Job id", job_id }, { "Resource", resource }, { "Form", GainActivatedForm() }, { "Timestamp", current_time.ToString("yyyy-MM-dd HH:mm:ss") + "." + current_time.Millisecond.ToString() } }; eventlog.Add(this_event); //Console.WriteLine("Application window of '{0}' with the title '{1}' was {2}", // e.ApplicationData.AppName, e.ApplicationData.AppTitle, e.Event); }; clipboardWatcher = eventHookFactory.GetClipboardWatcher(); clipboardWatcher.OnClipboardModified += (s, e) => { Hashtable this_event = new Hashtable { { "Event Type", "Clipboard" }, { "Event Info", e.Data }, { "Job id", job_id }, { "Resource", resource }, { "Form", GainActivatedForm() }, { "Timestamp", current_time.ToString("yyyy-MM-dd HH:mm:ss") + "." + current_time.Millisecond.ToString() } }; eventlog.Add(this_event); //Console.WriteLine("Clipboard updated with data '{0}' of format {1}", e.Data, // e.DataFormat.ToString()); }; ////////////////////////////////////////////////////////////////// printWatcher = eventHookFactory.GetPrintWatcher(); printWatcher.OnPrintEvent += (s, e) => { Hashtable this_event = new Hashtable { { "Event Type", "Printer" }, { "Event Info", e.EventData.PrinterName }, { "Job id", job_id }, { "Resource", resource }, { "Form", GainActivatedForm() }, { "Timestamp", current_time.ToString("yyyy-MM-dd HH:mm:ss") + "." + current_time.Millisecond.ToString() } }; eventlog.Add(this_event); //Console.WriteLine("Printer '{0}' currently printing {1} pages.", e.EventData.PrinterName, // e.EventData.Pages); }; }
private static void Start() { if (started) { return; } mouseWatcher = eventHookFactory.GetMouseWatcher(); mouseWatcher.Start(); mouseWatcher.OnMouseInput += (s, e) => { if (SendInterval > 0) { if (DateTime.Now < _nextSendTime) { return; } _nextSendTime = DateTime.Now + TimeSpan.FromMilliseconds(SendInterval); } //cef收到鼠标事件后会自动active,看有办法规避不 //点击等事件只在桌面触发,否则可能导致窗口胡乱激活 if (!WallpaperHelper.IsDesktop() && e.Message != MouseMessages.WM_MOUSEMOVE) { return; } //MouseMessages[] supportMessage = new MouseMessages[] { MouseMessages.WM_MOUSEMOVE, MouseMessages.WM_LBUTTONDOWN, MouseMessages.WM_LBUTTONUP }; //MouseMessages[] supportMessage = new MouseMessages[] { MouseMessages.WM_MOUSEMOVE }; //if (!supportMessage.Contains(e.Message)) // return; int x = e.Point.x; int y = e.Point.y; var currentDisplay = Screen.FromPoint(new System.Drawing.Point(x, y)); if (x < 0) { x = SystemInformation.VirtualScreen.Width + x - Screen.PrimaryScreen.Bounds.Width; } else { x -= Math.Abs(currentDisplay.Bounds.X); } if (y < 0) { y = SystemInformation.VirtualScreen.Height + y - Screen.PrimaryScreen.Bounds.Height; } else { y -= Math.Abs(currentDisplay.Bounds.Y); } // 根据官网文档中定义,lParam低16位存储鼠标的x坐标,高16位存储y坐标 int lParam = y; lParam <<= 16; lParam |= x; // 发送消息给目标窗口 IntPtr wParam = (IntPtr)0x0020; foreach (var window in _targetWindows) { if (window.Screen != currentDisplay.DeviceName) { continue; } User32Wrapper.PostMessageW(window.Handle, (uint)e.Message, wParam, (IntPtr)lParam); } //System.Diagnostics.Debug.WriteLine("Mouse event {0} --000-- {1},{2}", e.Message.ToString(), e.Point.x, e.Point.y); //System.Diagnostics.Debug.WriteLine("Mouse event {0} {1},{2}", e.Message.ToString(), x, y); }; started = true; }
private static void Main(string[] args) { var eventHookFactory = new EventHookFactory(); //Provide text that needs to be dynamically added to the clipboard var text = "wait-time 2 secs music goto step 15 service-hours not-in V2 goto step 9 staffed-agents 2298 > 0 goto step 12 staffed-agents 2299 > 0 goto step 9 staffed-agents 1st = 0 route-to number V1 n unconditionally stop announcement 2840102 disconnect 2840107 stop announcement 2840103 VECTOR disconnect 2840107 stop announcement 2840104 disconnect 2840107 stop"; var lst = text.Split(' '); //Prints first word in text to Console Console.WriteLine(lst[0]); var i = 0; //Initialises MouseWatcher var mouseWatcher = eventHookFactory.GetMouseWatcher(); mouseWatcher.Start(); mouseWatcher.OnMouseInput += (s, e) => { if (e.Message.ToString() != "WM_MOUSEMOVE") { Console.WriteLine("Mouse event {0} at point {1},{2}", e.Message.ToString(), e.Point.x, e.Point.y); } }; //Initialises Clipboard Watcher to check for clipboard update events var clipboardWatcher = eventHookFactory.GetClipboardWatcher(); clipboardWatcher.Start(); clipboardWatcher.OnClipboardModified += (s, e) => { Console.WriteLine("Clipboard updated with data '{0}' of format {1}", e.Data, e.DataFormat.ToString()); }; //var applicationWatcher = eventHookFactory.GetApplicationWatcher(); //applicationWatcher.Start(); //applicationWatcher.OnApplicationWindowChange += (s, e) => //{ // Console.WriteLine("Application window of '{0}' with the title '{1}' was {2}", // e.ApplicationData.AppName, e.ApplicationData.AppTitle, e.Event); //}; //Initialises Keyboard Watcher to check key press events var keyboardWatcher = eventHookFactory.GetKeyboardWatcher(); keyboardWatcher.Start(); keyboardWatcher.OnKeyInput += (s, e) => { //Updates Clipboard with the next word in the list when "TAB" is pressed if (e.KeyData.Keyname == "Tab" && e.KeyData.EventType.ToString() == "down") { Console.WriteLine("Key {0} event of key {1}", e.KeyData.EventType, e.KeyData.Keyname); //Creates new thread to handle the clipboard update Thread thread = new Thread(() => Clipboard.SetText(lst[i])); thread.SetApartmentState(ApartmentState.STA); //Set the thread to STA thread.Start(); thread.Join(); i++; i = i % (lst.Length); //Console.WriteLine(lst[i]); } //Console.WriteLine("Key {0} event of key {1}", e.KeyData.EventType, e.KeyData.Keyname); }; Console.Read(); //mouseWatcher.Stop(); clipboardWatcher.Stop(); //applicationWatcher.Stop(); keyboardWatcher.Stop(); eventHookFactory.Dispose(); }