コード例 #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 EventHookRecorder()
        {
            var eventHookFactory = new EventHookFactory();

            mouseWatcher    = eventHookFactory.GetMouseWatcher();
            keyboardWatcher = eventHookFactory.GetKeyboardWatcher();
        }
コード例 #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
 private void Validated(IUserActionCallback validationCallback)
 {
     validated = true;
     Console.WriteLine("validated!");
     KeyboardWatcher.Stop();
     MouseWatcher.Stop();
     validationCallback.OnBtnValidated();
 }
コード例 #6
0
        protected override void OnExit(ExitEventArgs e)
        {
            trayIcon.Dispose();
            carnac.Dispose();
            MouseWatcher.Stop();
            ProcessUtilities.DestroyMutex();

            base.OnExit(e);
        }
コード例 #7
0
ファイル: AccelGUI.cs プロジェクト: termhn/rawaccel
        public AccelGUI(
            RawAcceleration accelForm,
            AccelCalculator accelCalculator,
            AccelCharts accelCharts,
            SettingsManager settings,
            ApplyOptions applyOptions,
            Button writeButton,
            ButtonBase toggleButton,
            MouseWatcher mouseWatcher,
            ToolStripMenuItem scaleMenuItem)
        {
            AccelForm         = accelForm;
            AccelCalculator   = accelCalculator;
            AccelCharts       = accelCharts;
            ApplyOptions      = applyOptions;
            WriteButton       = writeButton;
            ToggleButton      = (CheckBox)toggleButton;
            ScaleMenuItem     = scaleMenuItem;
            Settings          = settings;
            DefaultButtonFont = WriteButton.Font;
            SmallButtonFont   = new Font(WriteButton.Font.Name, WriteButton.Font.Size * Constants.SmallButtonSizeFactor);
            MouseWatcher      = mouseWatcher;

            ScaleMenuItem.Click   += new System.EventHandler(OnScaleMenuItemClick);
            WriteButton.Click     += new System.EventHandler(OnWriteButtonClick);
            ToggleButton.Click    += new System.EventHandler(OnToggleButtonClick);
            AccelForm.FormClosing += new FormClosingEventHandler(SaveGUISettingsOnClose);

            ButtonTimerInterval = Convert.ToInt32(DriverInterop.WriteDelayMs);
            ButtonTimer         = new Timer();
            ButtonTimer.Tick   += new System.EventHandler(OnButtonTimerTick);

            ChartRefresh = SetupChartTimer();

            bool settingsActive = Settings.Startup();

            SettingsNotDefault = !Settings.RawAccelSettings.IsDefaultEquivalent();

            if (settingsActive)
            {
                LastToggleChecked    = SettingsNotDefault;
                ToggleButton.Enabled = LastToggleChecked;
                RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings);
            }
            else
            {
                DriverSettings active           = DriverInterop.GetActiveSettings();
                bool           activeNotDefault = !RawAccelSettings.IsDefaultEquivalent(active);

                LastToggleChecked    = activeNotDefault;
                ToggleButton.Enabled = SettingsNotDefault || activeNotDefault;
                RefreshOnRead(active);
            }

            SetupButtons();
            AccelForm.DoResize();
        }
コード例 #8
0
 private void Undo(IUserActionCallback userAcitonCallback)
 {
     undoed = true;
     KeyboardWatcher.Stop();
     MouseWatcher.Stop();
     userAcitonCallback.OnBtnUndo();
     Console.WriteLine("undo!");
     //UnblockUndo(5000);
 }
コード例 #9
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();
        }
コード例 #10
0
        public BeamgunViewModel()
        {
            var dictionary      = new RegistryBackedDictionary();
            var beamgunSettings = new BeamgunSettings(dictionary);

            BeamgunState = new BeamgunState(beamgunSettings)
            {
                MainWindowVisibility = Visibility.Hidden
            };
            // TODO: This bi-directional relationship feels bad.
            dictionary.BadCastReport += BeamgunState.AppendToAlert;
            BeamgunState.Disabler     = new Disabler(BeamgunState);
            BeamgunState.Disabler.Enable();
            DisableCommand     = new DisableCommand(this, beamgunSettings);
            TrayIconCommand    = new TrayIconCommand(this);
            LoseFocusCommand   = new DeactivatedCommand(this);
            ResetCommand       = new ResetCommand(this);
            ExitCommand        = new ExitCommand(this);
            ClearAlertsCommand = new ClearAlertsCommand(this);
            _keystrokeHooker   = InstallKeystrokeHooker();
            _usbStorageGuard   = InstallUsbStorageGuard(beamgunSettings);
            _alarm             = InstallAlarm(beamgunSettings);
            _networkWatcher    = new NetworkWatcher(beamgunSettings,
                                                    new NetworkAdapterDisabler(),
                                                    x => BeamgunState.AppendToAlert(x),
                                                    x =>
            {
                _alarm.Trigger(x);
                BeamgunState.SetGraphicsLanAlert();
            },
                                                    () => BeamgunState.Disabler.IsDisabled);
            _keyboardWatcher = new KeyboardWatcher(beamgunSettings,
                                                   new WorkstationLocker(),
                                                   x => BeamgunState.AppendToAlert(x),
                                                   x =>
            {
                _alarm.Trigger(x);
                BeamgunState.SetGraphicsKeyboardAlert();
            },
                                                   () => BeamgunState.Disabler.IsDisabled);
            _mouseWatcher = new MouseWatcher(beamgunSettings,
                                             new WorkstationLocker(),
                                             x => BeamgunState.AppendToAlert(x),
                                             x =>
            {
                _alarm.Trigger(x);
                BeamgunState.SetGraphicsMouseAlert();
            },
                                             () => BeamgunState.Disabler.IsDisabled);
            var checker = new VersionChecker();

            _updateTimer = new VersionCheckerTimer(beamgunSettings,
                                                   checker,
                                                   x => BeamgunState.AppendToAlert(x));
        }
コード例 #11
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();
 }
コード例 #12
0
 public void AskForRightClickOnBar()
 {
     MouseWatcher.Start();
     MouseWatcher.OnMouseInput += (s, e) =>
     {
         ExeWindowTitleReader.GetActiveWindowTitle();
         if (e.Message == EventHook.Hooks.MouseMessages.WM_RBUTTONUP)
         {
             MouseWatcher.Stop();
         }
     };
 }
コード例 #13
0
        public void RefreshOnRead(DriverSettings args)
        {
            UpdateShownActiveValues(args);
            UpdateGraph(args);

            UpdateInputManagers = () =>
            {
                MouseWatcher.UpdateHandles(args.deviceID);
                DeviceIDManager.Update(args.deviceID);
            };

            UpdateInputManagers();
        }
コード例 #14
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();
        }
コード例 #15
0
        public void OnExit()
        {
            //keyboardMouseSimulator.releaseCtrl();

            ClipboardWatcher.Stop();
            KeyboardWatcher.Stop();
            MouseWatcher.Stop();
            Console.WriteLine("done!");
            Application.Exit();
            try
            {
                Environment.Exit(1);
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
        }
コード例 #16
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();
        }
コード例 #17
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();
         }
     };
 }
コード例 #18
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;
            }
        }
コード例 #19
0
 public void Pause()
 {
     MouseWatcher.Stop();
 }
コード例 #20
0
 public void Start()
 {
     MouseWatcher.Start();
 }
コード例 #21
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;
        }
コード例 #22
0
ファイル: AccelGUIFactory.cs プロジェクト: Toxicoria/rawaccel
        public static AccelGUI Construct(
            RawAcceleration form,
            ManagedAccel activeAccel,
            Chart accelerationChart,
            Chart accelerationChartY,
            Chart velocityChart,
            Chart velocityChartY,
            Chart gainChart,
            Chart gainChartY,
            ComboBox accelTypeDropX,
            ComboBox accelTypeDropY,
            Button writeButton,
            ButtonBase toggleButton,
            ToolStripMenuItem showVelocityGainToolStripMenuItem,
            ToolStripMenuItem showLastMouseMoveMenuItem,
            ToolStripMenuItem wholeVectorToolStripMenuItem,
            ToolStripMenuItem byVectorComponentToolStripMenuItem,
            ToolStripMenuItem velocityGainCapToolStripMenuItem,
            ToolStripMenuItem legacyCapToolStripMenuItem,
            ToolStripMenuItem gainOffsetToolStripMenuItem,
            ToolStripMenuItem legacyOffsetToolStripMenuItem,
            ToolStripMenuItem autoWriteMenuItem,
            ToolStripMenuItem scaleMenuItem,
            ToolStripTextBox dpiTextBox,
            ToolStripTextBox pollRateTextBox,
            TextBox sensitivityBoxX,
            TextBox sensitivityBoxY,
            TextBox rotationBox,
            TextBox weightBoxX,
            TextBox weightBoxY,
            TextBox capBoxX,
            TextBox capBoxY,
            TextBox offsetBoxX,
            TextBox offsetBoxY,
            TextBox accelerationBoxX,
            TextBox accelerationBoxY,
            TextBox scaleBoxX,
            TextBox scaleBoxY,
            TextBox limitBoxX,
            TextBox limitBoxY,
            TextBox expBoxX,
            TextBox expBoxY,
            TextBox midpointBoxX,
            TextBox midpointBoxY,
            CheckBox sensXYLock,
            CheckBox byComponentXYLock,
            Label lockXYLabel,
            Label sensitivityLabel,
            Label rotationLabel,
            Label weightLabelX,
            Label weightLabelY,
            Label capLabelX,
            Label capLabelY,
            Label offsetLabelX,
            Label offsetLabelY,
            Label constantOneLabelX,
            Label constantOneLabelY,
            Label scaleLabelX,
            Label scaleLabelY,
            Label limitLabelX,
            Label limitLabelY,
            Label expLabelX,
            Label expLabelY,
            Label constantThreeLabelX,
            Label constantThreeLabelY,
            Label activeValueTitleX,
            Label activeValueTitleY,
            Label sensitivityActiveXLabel,
            Label sensitivityActiveYLabel,
            Label rotationActiveLabel,
            Label weightActiveXLabel,
            Label weightActiveYLabel,
            Label capActiveXLabel,
            Label capActiveYLabel,
            Label offsetActiveLabelX,
            Label offsetActiveLabelY,
            Label accelerationActiveLabelX,
            Label accelerationActiveLabelY,
            Label scaleActiveLabelX,
            Label scaleActiveLabelY,
            Label limitActiveLabelX,
            Label limitActiveLabelY,
            Label expActiveLabelX,
            Label expActiveLabelY,
            Label midpointActiveLabelX,
            Label midpointActiveLabelY,
            Label accelTypeActiveLabelX,
            Label accelTypeActiveLabelY,
            Label optionSetXTitle,
            Label optionSetYTitle,
            Label mouseLabel)
        {
            var accelCalculator = new AccelCalculator(
                new Field(dpiTextBox.TextBox, form, Constants.DefaultDPI),
                new Field(pollRateTextBox.TextBox, form, Constants.DefaultPollRate));

            var accelCharts = new AccelCharts(
                form,
                new ChartXY(accelerationChart, accelerationChartY, Constants.SensitivityChartTitle),
                new ChartXY(velocityChart, velocityChartY, Constants.VelocityChartTitle),
                new ChartXY(gainChart, gainChartY, Constants.GainChartTitle),
                showVelocityGainToolStripMenuItem,
                showLastMouseMoveMenuItem,
                writeButton,
                accelCalculator);

            var sensitivity = new OptionXY(
                sensitivityBoxX,
                sensitivityBoxY,
                sensXYLock,
                form,
                1,
                sensitivityLabel,
                new ActiveValueLabelXY(
                    new ActiveValueLabel(sensitivityActiveXLabel, activeValueTitleX),
                    new ActiveValueLabel(sensitivityActiveYLabel, activeValueTitleX)),
                "Sens Multiplier");

            var rotation = new Option(
                rotationBox,
                form,
                0,
                rotationLabel,
                0,
                new ActiveValueLabel(rotationActiveLabel, activeValueTitleX),
                "Rotation");

            var optionSetYLeft = rotation.Left + rotation.Width;

            var weightX = new Option(
                weightBoxX,
                form,
                1,
                weightLabelX,
                0,
                new ActiveValueLabel(weightActiveXLabel, activeValueTitleX),
                "Weight");

            var weightY = new Option(
                weightBoxY,
                form,
                1,
                weightLabelY,
                optionSetYLeft,
                new ActiveValueLabel(weightActiveYLabel, activeValueTitleY),
                "Weight");

            var capX = new Option(
                capBoxX,
                form,
                0,
                capLabelX,
                0,
                new ActiveValueLabel(capActiveXLabel, activeValueTitleX),
                "Cap");

            var capY = new Option(
                capBoxY,
                form,
                0,
                capLabelY,
                optionSetYLeft,
                new ActiveValueLabel(capActiveYLabel, activeValueTitleY),
                "Cap");

            var offsetX = new Option(
                offsetBoxX,
                form,
                0,
                offsetLabelX,
                0,
                new ActiveValueLabel(offsetActiveLabelX, activeValueTitleX),
                "Offset");

            var offsetY = new Option(
                offsetBoxY,
                form,
                0,
                offsetLabelY,
                optionSetYLeft,
                new ActiveValueLabel(offsetActiveLabelY, activeValueTitleY),
                "Offset");

            var offsetOptionsX = new OffsetOptions(
                gainOffsetToolStripMenuItem,
                legacyOffsetToolStripMenuItem,
                offsetX);

            var offsetOptionsY = new OffsetOptions(
                gainOffsetToolStripMenuItem,
                legacyOffsetToolStripMenuItem,
                offsetY);

            var accelerationX = new Option(
                new Field(accelerationBoxX, form, 0),
                constantOneLabelX,
                new ActiveValueLabel(accelerationActiveLabelX, activeValueTitleX),
                0);

            var accelerationY = new Option(
                new Field(accelerationBoxY, form, 0),
                constantOneLabelY,
                new ActiveValueLabel(accelerationActiveLabelY, activeValueTitleY),
                optionSetYLeft);

            var scaleX = new Option(
                new Field(scaleBoxX, form, 0),
                scaleLabelX,
                new ActiveValueLabel(scaleActiveLabelX, activeValueTitleX),
                0);

            var scaleY = new Option(
                new Field(scaleBoxY, form, 0),
                scaleLabelY,
                new ActiveValueLabel(scaleActiveLabelY, activeValueTitleY),
                optionSetYLeft);

            var limitX = new Option(
                new Field(limitBoxX, form, 2),
                limitLabelX,
                new ActiveValueLabel(limitActiveLabelX, activeValueTitleX),
                0);

            var limitY = new Option(
                new Field(limitBoxY, form, 2),
                limitLabelY,
                new ActiveValueLabel(limitActiveLabelY, activeValueTitleY),
                optionSetYLeft);

            var exponentX = new Option(
                new Field(expBoxX, form, 2),
                expLabelX,
                new ActiveValueLabel(expActiveLabelX, activeValueTitleX),
                0);

            var exponentY = new Option(
                new Field(expBoxY, form, 2),
                expLabelY,
                new ActiveValueLabel(expActiveLabelY, activeValueTitleY),
                optionSetYLeft);

            var midpointX = new Option(
                new Field(midpointBoxX, form, 0),
                constantThreeLabelX,
                new ActiveValueLabel(midpointActiveLabelX, activeValueTitleX),
                0);

            var midpointY = new Option(
                new Field(midpointBoxY, form, 0),
                constantThreeLabelY,
                new ActiveValueLabel(midpointActiveLabelY, activeValueTitleY),
                optionSetYLeft);

            var capOptionsX = new CapOptions(
                velocityGainCapToolStripMenuItem,
                legacyCapToolStripMenuItem,
                capX);

            var capOptionsY = new CapOptions(
                velocityGainCapToolStripMenuItem,
                legacyCapToolStripMenuItem,
                capY);

            var accelerationOptionsX = new AccelTypeOptions(
                accelTypeDropX,
                accelerationX,
                scaleX,
                capOptionsX,
                weightX,
                offsetOptionsX,
                limitX,
                exponentX,
                midpointX,
                writeButton,
                new ActiveValueLabel(accelTypeActiveLabelX, activeValueTitleX));

            var accelerationOptionsY = new AccelTypeOptions(
                accelTypeDropY,
                accelerationY,
                scaleY,
                capOptionsY,
                weightY,
                offsetOptionsY,
                limitY,
                exponentY,
                midpointY,
                writeButton,
                new ActiveValueLabel(accelTypeActiveLabelY, activeValueTitleY));

            var optionsSetX = new AccelOptionSet(
                optionSetXTitle,
                activeValueTitleX,
                rotationBox.Top + rotationBox.Height + Constants.OptionVerticalSeperation,
                accelerationOptionsX);

            var optionsSetY = new AccelOptionSet(
                optionSetYTitle,
                activeValueTitleY,
                rotationBox.Top + rotationBox.Height + Constants.OptionVerticalSeperation,
                accelerationOptionsY);

            var applyOptions = new ApplyOptions(
                wholeVectorToolStripMenuItem,
                byVectorComponentToolStripMenuItem,
                byComponentXYLock,
                optionsSetX,
                optionsSetY,
                sensitivity,
                rotation,
                lockXYLabel,
                accelCharts);

            var settings = new SettingsManager(
                activeAccel,
                accelCalculator.DPI,
                accelCalculator.PollRate,
                autoWriteMenuItem,
                showLastMouseMoveMenuItem,
                showVelocityGainToolStripMenuItem);

            var mouseWatcher = new MouseWatcher(form, mouseLabel, accelCharts, accelCalculator.PollRate);

            return(new AccelGUI(
                       form,
                       accelCalculator,
                       accelCharts,
                       settings,
                       applyOptions,
                       writeButton,
                       toggleButton,
                       mouseWatcher,
                       scaleMenuItem));
        }
コード例 #23
0
ファイル: MainWindow.xaml.cs プロジェクト: ywscr/KeyMouseHook
        public MainWindow()
        {
            InitializeComponent();
            keyboardWatcher = eventHookFactory.GetKeyboardWatcher();
            keyboardWatcher.OnKeyboardInput += (s, e) =>
            {
                if (_macroEvents != null)
                {
                    _macroEvents.Add(e);
                }

                if (e.KeyMouseEventType == MacroEventType.KeyPress)
                {
                    var keyEvent = (KeyPressEventArgs)e.EventArgs;
                    Log(string.Format("Key {0}\t\t{1}\n", keyEvent.KeyChar, e.KeyMouseEventType));
                }
                else
                {
                    var keyEvent = (System.Windows.Forms.KeyEventArgs)e.EventArgs;
                    Log(string.Format("Key {0}\t\t{1}\n", keyEvent.KeyCode, e.KeyMouseEventType));
                }
            };

            mouseWatcher = eventHookFactory.GetMouseWatcher();
            mouseWatcher.OnMouseInput += (s, e) =>
            {
                if (_macroEvents != null)
                {
                    _macroEvents.Add(e);
                }
                switch (e.KeyMouseEventType)
                {
                case MacroEventType.MouseMove:
                    var mouseEvent = (System.Windows.Forms.MouseEventArgs)e.EventArgs;
                    LogMouseLocation(mouseEvent.X, mouseEvent.Y);
                    break;

                case MacroEventType.MouseWheel:
                    mouseEvent = (System.Windows.Forms.MouseEventArgs)e.EventArgs;
                    LogMouseWheel(mouseEvent.Delta);
                    break;

                case MacroEventType.MouseClick:
                case MacroEventType.MouseDown:
                case MacroEventType.MouseUp:
                    mouseEvent = (System.Windows.Forms.MouseEventArgs)e.EventArgs;
                    Log(string.Format("Mouse {0}\t\t{1}\n", mouseEvent.Button, e.KeyMouseEventType));
                    break;

                case MacroEventType.MouseDownExt:
                    MouseEventExtArgs downExtEvent = (MouseEventExtArgs)e.EventArgs;
                    if (downExtEvent.Button != MouseButtons.Right)
                    {
                        Log(string.Format("Mouse Down \t\t {0}\n", downExtEvent.Button));
                        return;
                    }
                    Log(string.Format("Mouse Down \t\t {0} Suppressed\n", downExtEvent.Button));
                    downExtEvent.Handled = true;
                    break;

                case MacroEventType.MouseWheelExt:
                    MouseEventExtArgs wheelEvent = (MouseEventExtArgs)e.EventArgs;
                    labelWheel.Content = string.Format("Wheel={0:000}", wheelEvent.Delta);
                    Log("Mouse Wheel Move Suppressed.\n");
                    wheelEvent.Handled = true;
                    break;
                }
            };
        }
コード例 #24
0
 internal void StopHooking()
 {
     KeyboardWatcher.Stop();
     MouseWatcher.Stop();
 }
コード例 #25
0
ファイル: AccelGUI.cs プロジェクト: termhn/rawaccel
 private void OnChartTimerTick(object sender, EventArgs e)
 {
     AccelCharts.DrawLastMovement();
     MouseWatcher.UpdateLastMove();
 }
コード例 #26
0
 public void StopLogger() => MouseWatcher.Stop();
コード例 #27
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);
            }
        }
コード例 #28
0
        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);
            };
        }
コード例 #29
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);
        }
コード例 #30
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++;
                }
            };
        }