コード例 #1
0
        public MainWindow()
        {
            InitializeComponent();

            KeyboardWatcher.Start();
            KeyboardWatcher.OnKeyInput += (s, e) =>
            {
                Debug.WriteLine(string.Format("Key {0} event of key {1}", e.KeyData.EventType, e.KeyData.Keyname));
            };

            MouseWatcher.Start();
            MouseWatcher.OnMouseInput += (s, e) =>
            {
                Debug.WriteLine(string.Format("Mouse event {0} at point {1},{2}", e.Message.ToString(), e.Point.x, e.Point.y));
            };

            ClipboardWatcher.Start();
            ClipboardWatcher.OnClipboardModified += (s, e) =>
            {
                Debug.WriteLine(string.Format("Clipboard updated with data '{0}' of format {1}", e.Data, e.DataFormat.ToString()));
            };

            ApplicationWatcher.Start();
            ApplicationWatcher.OnApplicationWindowChange += (s, e) =>
            {
                Debug.WriteLine(string.Format("Application window of '{0}' with the title '{1}' was {2}", e.ApplicationData.AppName, e.ApplicationData.AppTitle, e.Event));
            };

            PrintWatcher.Start();
            PrintWatcher.OnPrintEvent += (s, e) =>
            {
                Debug.WriteLine(string.Format("Printer '{0}' currently printing {1} pages.", e.EventData.PrinterName, e.EventData.Pages));
            };
        }
コード例 #2
0
 public void StartWatch(IKeyboardMouseEvents events = null)
 {
     Thread.Sleep(1000);
     _macroEvents = new List <MacroEvent>();
     keyboardWatcher.Start(events);
     mouseWatcher.Start(events);
 }
コード例 #3
0
        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;
        }
コード例 #4
0
        public void WaitForUserAction(IUserActionCallback userAcitonCallback)
        {
            KeyboardWatcher.Start();
            MouseWatcher.Start();
            validated = false;
            undoed    = false;
            MouseWatcher.OnMouseInput += (s, e) =>
            {
                if (e.Message.ToString().Equals(PathForm.GetValidationBtnName()) && !validated)
                {
                    Validated(userAcitonCallback);
                }
            };

            KeyboardWatcher.OnKeyInput += (s, e) =>
            {
                Console.WriteLine("btn name: " + e.KeyData.Keyname);
                if (e.KeyData.Keyname.Equals(UNDO) && !undoed)
                {
                    Undo(userAcitonCallback);
                }


                if (e.KeyData.Keyname.Equals(PathForm.GetValidationBtnName()) && !validated)
                {
                    Validated(userAcitonCallback);
                }
            };
        }
コード例 #5
0
        //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();
        }
コード例 #6
0
 public void StartLogger()
 {
     MouseWatcher.OnMouseInput += (s, e) =>
     {
         if (CheckEvent(e.Message.ToString())) // Button down event
         {
             WriteLog($"Mouse: {e.Message.ToString()} at point {e.Point.x},{e.Point.y}");
         }
     };
     MouseWatcher.Start();
 }
コード例 #7
0
        private void button3_Click(object sender, EventArgs e) //start
        {
            //MessageBox.Show(resource);
            keyboardWatcher.Start();
            mouseWatcher.Start();
            clipboardWatcher.Start();
            applicationWatcher.Start();
            printWatcher.Start();

            label4.Text = "Recording";
        }
コード例 #8
0
 public void AskForRightClickOnBar()
 {
     MouseWatcher.Start();
     MouseWatcher.OnMouseInput += (s, e) =>
     {
         ExeWindowTitleReader.GetActiveWindowTitle();
         if (e.Message == EventHook.Hooks.MouseMessages.WM_RBUTTONUP)
         {
             MouseWatcher.Stop();
         }
     };
 }
コード例 #9
0
        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();
        }
コード例 #10
0
        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();
        }
コード例 #11
0
 private void MouseHook()
 {
     MouseWatcher.Start();
     MouseWatcher.OnMouseInput += (s, e) =>
     {
         //Console.WriteLine(string.Format("Mouse event {0} at point {1},{2}", e.Message.ToString(), e.Point.x, e.Point.y));
         if (e.Message.ToString().Contains("BUTTONDOWN"))
         {
             if (!string.IsNullOrWhiteSpace(prevClick) && prevClick != e.Message.ToString())
             {
                 this.Invoke(new MethodInvoker(delegate
                 {
                     this.Location = new Point(e.Point.x, e.Point.y);
                     this.ShowLauncher();
                 }));
             }
             prevClick = e.Message.ToString();
         }
     };
 }
コード例 #12
0
        public void StartHooking()
        {
            KeyboardWatcher.Start();
            MouseWatcher.Start();

            MouseWatcher.OnMouseInput  += MouseWatcher_OnMouseInput;
            KeyboardWatcher.OnKeyInput += KeyboardWatcher_OnKeyInput;
            controller = new X360Controller();

            _outputReport = new byte[8];
            try
            {
                _scpBus = new ScpBus();

                _scpBus.PlugIn((int)1);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #13
0
 public void Start()
 {
     MouseWatcher.Start();
 }
コード例 #14
0
 public void Start()
 {
     mouseWatcher.Start();
     keyboardWatcher.Start();
 }
コード例 #15
0
ファイル: MainWindow.xaml.cs プロジェクト: ywscr/KeyMouseHook
 public void StartWatch(IKeyboardMouseEvents events = null)
 {
     _macroEvents = new List <MacroEvent>();
     keyboardWatcher.Start(events);
     mouseWatcher.Start(events);
 }
コード例 #16
0
 public void Start()
 {
     MouseWatcher.Start();
     KeyboardWatcher.Start();
     IsStarted = true;
 }
コード例 #17
0
        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;
        }
コード例 #18
0
        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);
            }
        }
コード例 #19
0
        protected override void OnStartup(StartupEventArgs e)
        {
            // Check if there was instance before this. If there was-close the current one.
            if (ProcessUtilities.ThisProcessIsAlreadyRunning())
            {
                ProcessUtilities.SetFocusToPreviousInstance("Carnac");
                Shutdown();
                return;
            }

            trayIcon = new CarnacTrayIcon();
            trayIcon.OpenPreferences += TrayIconOnOpenPreferences;
            var keyShowViewModel = new KeyShowViewModel(settings);

            keyShowView = new KeyShowView(keyShowViewModel);
            keyShowView.Show();

            carnac = new KeysController(keyShowViewModel.Messages, messageProvider, new ConcurrencyService(), settingsProvider);
            carnac.Start();

            MouseWatcher.OnMouseInput += (s, me) =>
            {
                if (!keyShowView.IsVisible)
                {
                    return;
                }
                var msg     = me.Message;
                var needAct = msg == MouseMessages.WM_LBUTTONUP || msg == MouseMessages.WM_RBUTTONUP;
                if (!needAct)
                {
                    return;
                }

                Dispatcher.Invoke(() =>
                {
                    keyShowViewModel.CursorPosition = keyShowView.PointFromScreen(new System.Windows.Point(me.Point.x, me.Point.y));
                    if (msg == MouseMessages.WM_LBUTTONUP)
                    {
                        keyShowView.LeftClick();
                    }
                    if (msg == MouseMessages.WM_RBUTTONUP)
                    {
                        keyShowView.RightClick();
                    }
                });
            };

            if (settings.ShowMouseClicks)
            {
                MouseWatcher.Start();
            }
            settings.PropertyChanged += (s, se) => {
                switch (se.PropertyName)
                {
                case "ShowMouseClicks":
                    if (this.settings.ShowMouseClicks)
                    {
                        MouseWatcher.Start();
                    }
                    else
                    {
                        MouseWatcher.Stop();
                    }
                    break;
                }
            };

#if !DEBUG
            if (settings.AutoUpdate)
            {
                Observable
                .Timer(TimeSpan.FromMinutes(5))
                .Subscribe(async x =>
                {
                    try
                    {
                        using (var mgr = UpdateManager.GitHubUpdateManager(carnacUpdateUrl))
                        {
                            await mgr.Result.UpdateApp();
                        }
                    }
                    catch
                    {
                        // Do something useful with the exception
                    }
                });
            }
#endif

            base.OnStartup(e);
        }
コード例 #20
0
        // 여기선 입력받는걸 바로 아래 리스트로 옴겨야됨.
        private void Macro_InputFromSystem_Click(object sender, EventArgs e)
        {
            if (Macro_Macrodata.Items.Count != 0)
            {
                MessageBox.Show("저장된것을 지우고 다시 시도해주세요.");
                return;
            }

            Enabled_false();

            int       play_count = -1;
            Stopwatch sw         = new Stopwatch();

            sw.Start();
            EventHandler <KeyInputEventArgs>        _KeyboardLambda = null;
            EventHandler <EventHook.MouseEventArgs> _MouseLambda    = null;

            KeyboardWatcher.Start();
            KeyboardWatcher.OnKeyInput += _KeyboardLambda = (s, ke) =>
            {
                // 멈춤 설정
                if (ke.KeyData.Keyname == "Pause")
                {
                    KeyboardWatcher.OnKeyInput -= _KeyboardLambda;
                    MouseWatcher.OnMouseInput  -= _MouseLambda;
                    KeyboardWatcher.Stop();
                    MouseWatcher.Stop();
                    sw.Stop();
                    Enabled_true();

                    return;
                }

                // 여기는 이벤트타입이 이벤트라는 enum이라 0또는 1일때의 텍스트로 바꿈
                string _event_type;
                if (ke.KeyData.EventType == 0)
                {
                    _event_type = "키보드 누름";
                }
                else
                {
                    _event_type = "키보드 뗌";
                }

                String[]     _rowdata = { sw.ElapsedMilliseconds.ToString(), _event_type, "" + ke.KeyData._Key };
                ListViewItem _row     = new ListViewItem(_rowdata);

                Macro_Macrodata.Items.Add(_row);

                play_count++;
            };

            MouseWatcher.Start();
            MouseWatcher.OnMouseInput += _MouseLambda = (s, ke) =>
            {
                if (Macro_Macrodata.Items.Count == 0 || ke.Message.ToString() != "WM_MOUSEMOVE")
                {
                    string _message = "";
                    if (ke.Message.ToString() == "WM_MOUSEMOVE")
                    {
                        _message = "마우스 이동";
                    }
                    else if (ke.Message.ToString() == "WM_LBUTTONDOWN")
                    {
                        _message = "마우스 왼쪽 버튼 누름";
                    }
                    else if (ke.Message.ToString() == "WM_LBUTTONUP")
                    {
                        _message = "마우스 왼쪽 버튼 뗌";
                    }
                    else if (ke.Message.ToString() == "WM_RBUTTONDOWN")
                    {
                        _message = "마우스 오른쪽 버튼 누름";
                    }
                    else if (ke.Message.ToString() == "WM_RBUTTONUP")
                    {
                        _message = "마우스 오른쪽 버튼 뗌";
                    }

                    // 마우스 위치값 더해서 문자열로
                    string _point = ke.Point.x + " " + ke.Point.y;

                    String[]     _rowdata = { sw.ElapsedMilliseconds.ToString(), _message, _point };
                    ListViewItem _row     = new ListViewItem(_rowdata);

                    Macro_Macrodata.Items.Add(_row);

                    play_count++;
                }
                else if (sw.ElapsedMilliseconds - Int32.Parse(Macro_Macrodata.Items[play_count].SubItems[0].Text) > 50)
                {
                    string _message = "";
                    if (ke.Message.ToString() == "WM_MOUSEMOVE")
                    {
                        _message = "마우스 이동";
                    }
                    else if (ke.Message.ToString() == "WM_LBUTTONDOWN")
                    {
                        _message = "마우스 왼쪽 버튼 누름";
                    }
                    else if (ke.Message.ToString() == "WM_LBUTTONUP")
                    {
                        _message = "마우스 왼쪽 버튼 뗌";
                    }
                    else if (ke.Message.ToString() == "WM_RBUTTONDOWN")
                    {
                        _message = "마우스 오른쪽 버튼 누름";
                    }
                    else if (ke.Message.ToString() == "WM_RBUTTONUP")
                    {
                        _message = "마우스 오른쪽 버튼 뗌";
                    }

                    // 마우스 위치값 더해서 문자열로
                    string _point = ke.Point.x + " " + ke.Point.y;

                    String[]     _rowdata = { sw.ElapsedMilliseconds.ToString(), _message, _point };
                    ListViewItem _row     = new ListViewItem(_rowdata);

                    Macro_Macrodata.Items.Add(_row);

                    play_count++;
                }
            };
        }