Пример #1
0
 private static void Hook_OnMouseActivity(object sender, CustomMouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left && e.IsMouseUp)
     {
         SendKeys.Send("^c");
     }
     else if (e.Delta != Delta && TextShown)
     {
         Delta = e.Delta;
         if (Delta > 0)
         {
             if (currentOpacity + 0.2 < 0.5)
             {
                 currentOpacity += 0.2;
             }
             else
             {
                 currentOpacity = 0.5;
             }
             ControlForm.Opacity = currentOpacity;
         }
         else if (Delta < 0)
         {
             if (currentOpacity - 0.2 > 0)
             {
                 currentOpacity -= 0.2;
             }
             else
             {
                 currentOpacity = 0;
             }
             ControlForm.Opacity = currentOpacity;
         }
     }
 }
 private void UserActivityHook_OnMouseActivity(object sender, CustomMouseEventArgs e)
 {
     if (IsMouseClickCapturing && e.Button == MouseButton.Left)
     {
         StopCapture();
     }
 }
Пример #3
0
        /// <summary>
        /// MouseHook event method, detects the mouse clicks.
        /// </summary>
        private void MouseHookTarget(object sender, CustomMouseEventArgs args)
        {
            if (WindowState == WindowState.Minimized)
            {
                return;
            }

            _recordClicked = (args.Button == MouseButton.Left || args.Button == MouseButton.Right) || (Mouse.LeftButton == MouseButtonState.Pressed || Mouse.RightButton == MouseButtonState.Pressed);
        }
Пример #4
0
        void _hook_OnMouseActivity(object sender, CustomMouseEventArgs e)
        {
            //Console.WriteLine(String.Format(">> {0}{1} - {2}{3}", e.Button, e.Clicks, DateTime.Now.ToString("HH:mm:ss"), Environment.NewLine));

            if (e.Button == MouseButton.Left)
            {
                Thread.Sleep(100);

                keybd_event((byte)Keys.ControlKey, 0, 0, 0); //模拟按下ctrl
                keybd_event((byte)Keys.C, 0, 0, 0);          //模拟按下c
                keybd_event((byte)Keys.ControlKey, 0, 2, 0); //模拟松开ctrl
                keybd_event((byte)Keys.C, 0, 2, 0);          //模拟松开c

                Thread.Sleep(100);

                SearchWord(Clipboard.GetText());
                //Clipboard.Clear();
            }
        }
Пример #5
0
        /// <summary>
        /// MouseHook event method, detects the mouse clicks.
        /// </summary>
        private void MouseHookTarget(object sender, CustomMouseEventArgs args)
        {
            if (WindowState == WindowState.Minimized)
            {
                return;
            }

            _recordClicked = args.LeftButton == MouseButtonState.Pressed || args.RightButton == MouseButtonState.Pressed || args.MiddleButton == MouseButtonState.Pressed;

            if (!IsMouseCaptured || Mouse.Captured == null)
            {
                return;
            }

            #region Get Handle and Window Rect

            var handle = Native.WindowFromPoint(new Native.PointW {
                X = args.PosX, Y = args.PosY
            });
            var scale = this.Scale();

            if (_lastHandle != handle)
            {
                if (_lastHandle != IntPtr.Zero)
                {
                    Native.DrawFrame(_lastHandle, scale);
                }

                _lastHandle = handle;
                Native.DrawFrame(handle, scale);
            }

            var rect = Native.TrueWindowRectangle(handle);

            #endregion

            if (args.LeftButton == MouseButtonState.Pressed && Mouse.LeftButton == MouseButtonState.Pressed)
            {
                return;
            }

            #region Mouse Up

            Cursor = Cursors.Arrow;

            try
            {
                #region Try to get the process

                uint id = 0;
                Native.GetWindowThreadProcessId(handle, out id);
                var target = Process.GetProcesses().FirstOrDefault(p => p.Id == id);

                #endregion

                if (target != null && target.ProcessName == "ScreenToGif")
                {
                    return;
                }

                //Clear up the selected window frame.
                Native.DrawFrame(handle, scale);
                _lastHandle = IntPtr.Zero;

                #region Values

                //TODO: Test values with other versions of windows.
                var top    = (rect.Y / scale) - Constants.TopOffset + 0;
                var left   = (rect.X / scale) - Constants.LeftOffset + 0;
                var height = ((rect.Height + 1) / scale) + Constants.TopOffset + Constants.BottomOffset - 1;
                var width  = ((rect.Width + 1) / scale) + Constants.LeftOffset + Constants.RightOffset - 1;

                #endregion

                #region Validate

                if (top < SystemParameters.VirtualScreenTop)
                {
                    top = SystemParameters.VirtualScreenTop - 1;
                }
                if (left < SystemParameters.VirtualScreenLeft)
                {
                    left = SystemParameters.VirtualScreenLeft - 1;
                }
                if (SystemInformation.VirtualScreen.Height < (height + top) * scale) //TODO: Check if works with 2 screens.
                {
                    height = (SystemInformation.VirtualScreen.Height - top) / scale;
                }
                if (SystemInformation.VirtualScreen.Width < (width + left) * scale)
                {
                    width = (SystemInformation.VirtualScreen.Width - left) / scale;
                }

                #endregion

                Top    = top;
                Left   = left;
                Height = height;
                Width  = width;
            }
            catch (Exception ex)
            {
                LogWriter.Log(ex, "Error • Snap To Window");
            }
            finally
            {
                ReleaseMouseCapture();
            }

            #endregion
        }
Пример #6
0
        /// <summary>
        /// MouseHook event method, detects the mouse clicks.
        /// </summary>
        private void MouseHookTarget(object sender, CustomMouseEventArgs keyEventArgs)
        {
            if (WindowState == WindowState.Minimized)
            {
                return;
            }

            _recordClicked = keyEventArgs.Button == MouseButton.Left && keyEventArgs.State == MouseButtonState.Pressed;

            if (!IsMouseCaptured || Mouse.Captured == null)
            {
                return;
            }

            #region Get Handle and Window Rect

            var handle = Native.WindowFromPoint(new Native.PointW {
                X = keyEventArgs.PosX, Y = keyEventArgs.PosY
            });
            var scale = this.Scale();

            if (_lastHandle != handle)
            {
                if (_lastHandle != IntPtr.Zero)
                {
                    Native.DrawFrame(_lastHandle, scale);
                }

                _lastHandle = handle;
                Native.DrawFrame(handle, scale);
            }

            var rect = Native.TrueWindowRectangle(handle);

            #endregion

            if (keyEventArgs.State == MouseButtonState.Pressed)
            {
                return;
            }

            #region Mouse Up

            Cursor = Cursors.Arrow;

            try
            {
                #region Try to get the process

                Process target = null;// Process.GetProcesses().FirstOrDefault(p => p.Handle == handle);

                var processes = Process.GetProcesses();
                foreach (var proc in processes)
                {
                    try
                    {
                        if (proc.MainWindowHandle != IntPtr.Zero && proc.HandleCount > 0 && (proc.Handle == handle || proc.MainWindowHandle == handle))
                        {
                            target = proc;
                            break;
                        }
                    }
                    catch (Exception)
                    { }
                }

                #endregion

                if (target != null && target.ProcessName == "ScreenToGif")
                {
                    return;
                }

                //Clear up the selected window frame.
                Native.DrawFrame(handle, scale);
                _lastHandle = IntPtr.Zero;

                #region Values

                //TODO: Test values with other versions of windows.
                var top    = (rect.Y / scale) - Constants.TopOffset + 2;
                var left   = (rect.X / scale) - Constants.LeftOffset + 2;
                var height = ((rect.Height + 1) / scale) + Constants.TopOffset + Constants.BottomOffset - 5;
                var width  = ((rect.Width + 1) / scale) + Constants.LeftOffset + Constants.RightOffset - 5;

                #endregion

                #region Validate

                if (top < 0)
                {
                    top = 0 - 1;
                }
                if (left < 0)
                {
                    left = 0 - 1;
                }
                if (SystemInformation.VirtualScreen.Height < (height + top) * scale)
                {
                    height = (SystemInformation.VirtualScreen.Height - top) / scale;
                }
                if (SystemInformation.VirtualScreen.Width < (width + left) * scale)
                {
                    width = (SystemInformation.VirtualScreen.Width - left) / scale;
                }

                #endregion

                Top    = top;
                Left   = left;
                Height = height;
                Width  = width;
            }
            catch (Exception ex)
            {
                LogWriter.Log(ex, "Error • Snap To Window");
            }
            finally
            {
                ReleaseMouseCapture();
            }

            #endregion
        }
Пример #7
0
 void _hook_OnMouseActivity(object sender, CustomMouseEventArgs e)
 {
     MouseTextBox.Text += String.Format(">> {0} - {1}{2}", e.Button, DateTime.Now.ToString("HH:mm:ss"), Environment.NewLine);
     MouseTextBox.ScrollToLine(MouseTextBox.LineCount - 1);
 }
Пример #8
0
 /// <summary>
 /// MouseHook event method, detects the mouse clicks.
 /// </summary>
 private void MouseHookTarget(object sender, CustomMouseEventArgs keyEventArgs)
 {
     _recordClicked = keyEventArgs.Button == MouseButton.Left;
 }
Пример #9
0
        /// <summary>
        /// MouseHook event method, detects the mouse clicks.
        /// </summary>
        private void MouseHookTarget(object sender, CustomMouseEventArgs keyEventArgs)
        {
            _recordClicked = keyEventArgs.Button == MouseButton.Left && keyEventArgs.State == MouseButtonState.Pressed;
            _posCursor     = new System.Windows.Point(keyEventArgs.PosX, keyEventArgs.PosY);

            if (!IsMouseCaptured || Mouse.Captured == null || keyEventArgs.State == MouseButtonState.Pressed)
            {
                return;
            }

            //TODO: Make it work with parent handles...
            #region Mouse Up

            this.Cursor = Cursors.Arrow;

            try
            {
                var handle = Native.WindowFromPoint(keyEventArgs.PosX, keyEventArgs.PosY);
                var scale  = this.Scale();

                Process target = null;// Process.GetProcesses().FirstOrDefault(p => p.Handle == handle);

                var processes = Process.GetProcesses();
                foreach (var proc in processes)
                {
                    try
                    {
                        if (proc.MainWindowHandle != IntPtr.Zero && proc.HandleCount > 0 && (proc.Handle == handle || proc.MainWindowHandle == handle))
                        {
                            target = proc;
                            break;
                        }
                    }
                    catch (Exception)
                    {}
                }

                if (target == null || target.ProcessName == "ScreenToGif")
                {
                    return;
                }

                Native.RECT rect;
                Native.GetWindowRect(handle, out rect);

                #region Values

                //TODO: Check the position, different OS'.
                var top    = (rect.Top / scale) - 32;
                var left   = (rect.Left / scale) - 6;
                var height = ((rect.Bottom - rect.Top + 1) / scale) + 58;
                var width  = ((rect.Right - rect.Left + 1) / scale) + 12;

                #endregion

                #region Validate

                if (top < 0)
                {
                    top = 0;
                }
                if (left < 0)
                {
                    left = 0;
                }

                #endregion

                Top    = top;
                Left   = left;
                Height = height;
                Width  = width;
            }
            catch (Exception ex)
            {
                LogWriter.Log(ex, "Error • Snap To Window");
            }
            finally
            {
                ReleaseMouseCapture();
            }

            #endregion
        }