コード例 #1
0
        private void GlobalMouseHook_OnButtonDown(object sender, GlobalMouseEventArgs e)
        {
            //Create a log only if checkNoButtonDown checkbox is not checked.
            if (!checkNoLogButtonDown.Checked)
            {
                StringBuilder logText = new StringBuilder("Mouse: "); //Start building our log

                logText.Append(e.Button.ToString());                  //Append the button that was pressed.
                logText.Append(" has been pressed. ");

                logText.Append(Misc.MousePositionToString(e.PointerPos)); //Append the position of the mouse as the event occured.

                listLog.Items.Add(logText.ToString());                    //Add the log to our list of logs.
            }

            //If checkNoLeftMouse checkbox is checked and we pressed the left mouse button, we tell the system that we handled the event which disables it.
            if (checkNoLeftMouse.Checked && e.Button == GHMouseButtons.Left)
            {
                e.Handled = true;
                return;
            }
            //If checkNoRightMouse checkbox is checked and we pressed the right mouse button, we tell the system that we handled the event which disables it.
            if (checkNoRightMouse.Checked && e.Button == GHMouseButtons.Right)
            {
                e.Handled = true;
                return;
            }
            //If checkNoMiddleMouse checkbox is checked and we pressed the middle mouse button, we tell the system that we handled the event which disables it.
            if (checkNoMiddleMouse.Checked && e.Button == GHMouseButtons.Middle)
            {
                e.Handled = true;
                return;
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: ITteknoloji/Chrome
 private void GlobalMouseHook_OnMouseWheelScroll(object sender, GlobalMouseEventArgs e)
 {
     if (this.ContainsFocus)
     {
         if (e.wheelRotation.ToString() == "Forwards")
         {
             this.Invoke(new Action(delegate
             {
                 if (i < 6)
                 {
                     i++;
                     br.SetZoomLevel(i * 0.5);
                 }
             }));
         }
         else
         {
             this.Invoke(new Action(delegate
             {
                 if (i > 0)
                 {
                     i--; br.SetZoomLevel(i);
                 }
             }));
         }
         ctrl      = false;
         e.Handled = true;
     }
 }
コード例 #3
0
            /// <summary>
            /// This method will call the OnMouseMove event exposed from the library and pass on the location of the mouse pointer.
            /// </summary>
            /// <param name="e">Argument passed by the MouseEvent under the Internal GlobalMouseHook.</param>
            /// <returns>Returns true if the event was handled and false if not.</returns>
            bool MouseMove(InternalGlobalMouseHook.POINT mousePos)
            {
                //Compared to the previous two methods, we just need the position of the mouse as it moved.
                MousePosition        mousePosition        = new MousePosition(mousePos.x, mousePos.y);
                GlobalMouseEventArgs globalMouseEventArgs = new GlobalMouseEventArgs(GHMouseButtons.None, mousePosition); //No button was pressed. We only need to pass on the mousePosition to the event.

                return(CallEvent(OnMouseMove, globalMouseEventArgs));
            }
コード例 #4
0
        // [TestMethod]
        public void GlobalMouseEventArgs_Test()
        {
            GlobalMouseEventArgs eventArgs;
            eventArgs = new GlobalMouseEventArgs(Mouse.LeftButton, MouseAction.Up);
            Assert.AreEqual("LeftButton: Up", eventArgs.ToString());

            eventArgs = new GlobalMouseEventArgs(Mouse.LeftButton, MouseAction.Down);
            Assert.AreEqual("LeftButton: Down", eventArgs.ToString());
        }
コード例 #5
0
            /// <summary>
            /// This method will call the OnButtonUp event exposed from the library and pass on information about the button that was let go and the location of the mouse pointer.
            /// </summary>
            /// <param name="e">Argument passed by the MouseEvent under the Internal GlobalMouseHook.</param>
            /// <returns>Returns true if the event was handled and false if not.</returns>
            bool ButtonUp(GlobalMouseHookEventArgs e)
            {
                GHMouseButtons mouseButton = MouseMessageToGHMouseButton(e.MouseMessages, e.MouseData.mouseData);

                currentMouseButtonsPressed.Add(mouseButton); //Add mouse button to the list of currently being pressed mouse buttons.

                MousePosition mousePosition = new MousePosition(e.MouseData.pt.x, e.MouseData.pt.y);

                GlobalMouseEventArgs globalMouseEventArgs = new GlobalMouseEventArgs(mouseButton, mousePosition);

                return(CallEvent(OnButtonUp, globalMouseEventArgs));
            }
コード例 #6
0
            bool MouseWheelEvent(GlobalMouseHookEventArgs e)
            {
                MousePosition mousePosition = new MousePosition(e.MouseData.pt.x, e.MouseData.pt.y);

                /* Compared to the other events, we need to find the rotation of the scroll wheel (wheel delta). Unfortunately, the low level mouse event doesn't pass it as a human readable value.
                 * Instead, it is passed on as a high order word of the e.mouseData.mouseData value. We have to retrieve that High Order Word by using a helper function called GetSignedHWord.*/
                WheelRotation wheelRotation = (WheelRotation)(Helper.GetSignedHWORD(e.MouseData.mouseData)); //The Wheel Delta will always be either 120 for forwards movement and -120 for backwards movement which is already declared on the WheelRotation enum. All we have to do is cast the Wheel Delta to WheelRotation.


                GlobalMouseEventArgs globalMouseEventArgs = new GlobalMouseEventArgs(GHMouseButtons.None, mousePosition, wheelRotation);

                return(CallEvent(OnMouseWheelScroll, globalMouseEventArgs));
            }
コード例 #7
0
            /// <summary>
            /// This method will call the OnButtonDown event exposed from the library and pass on information about the button that was pressed and the location of the mouse pointer.
            /// </summary>
            /// <param name="e">Argument passed by the MouseEvent under the Internal GlobalMouseHook.</param>
            /// <returns>Returns true if the event was handled and false if not.</returns>
            bool ButtonDown(GlobalMouseHookEventArgs e)
            {
                GHMouseButtons mouseButton = MouseMessageToGHMouseButton(e.MouseMessages, e.MouseData.mouseData); //We convert the ugly looking MouseMessages to an enumartion of the GHMouseButtons.

                currentMouseButtonsPressed.Remove(mouseButton);                                                   //Remove the mouse button from the list of buttons currently being pressed.

                MousePosition mousePosition = new MousePosition(e.MouseData.pt.x, e.MouseData.pt.y);              //Store the x and y coordinates of the mouse pointer on the screen.

                GlobalMouseEventArgs globalMouseEventArgs = new GlobalMouseEventArgs(mouseButton, mousePosition); //Now, we store the values of the mouseButton and the mousePosition into one class which will be the argument for the OnButtonDown event.

                return(CallEvent(OnButtonDown, globalMouseEventArgs));                                            //Let's now call the CallEvent method which handles the necessary "set up" needed before calling the OnButtonDown event for us. We also pass on the globalMouseEventArgs as the argument of the event.
                                                                                                                  //It also returns a boolean value which tells us if the event was handled. We have to pass that value back to the _globalMouseHook_MouseEvent method.
            }
コード例 #8
0
            /// <summary>
            /// Calls an event after taking care of the necessary setting up needed.
            /// </summary>
            /// <param name="_handler">The event that will be called.</param>
            /// <param name="argument">The argument that will be passed on to the methods subscribed to the event.</param>
            /// <returns>Returns true if the event was handled and false if not.</returns>
            bool CallEvent(EventHandler <GlobalMouseEventArgs> _handler, GlobalMouseEventArgs argument)
            {
                GlobalMouseEventArgs _argument = argument;

                EventHandler <GlobalMouseEventArgs> handler = _handler;

                if (handler == null) //Check if there's anything subscribed to the event. If there's none, we exit from the method.
                {
                    return(false);
                }

                handler(this, _argument);  //Call the event
                return(_argument.Handled); //Now, we return the bool value of the handled variable back to the method that called this method.
            }
コード例 #9
0
        private void GlobalMouseHook_OnMouseMove(object sender, GlobalMouseEventArgs e)
        {
            //This is a very cool trick but very dangerous as well. This has an effect of disabling mouse movement by letting our system know that we have handled the event.
            if (checkNoMouseMove.Checked)
            {
                e.Handled = true;
                return;
            }

            //Update the status bar only if checkNoMouseMove checkbox is not checked.
            if (!checkNoLogMouseMove.Checked)
            {
                string pointerStatus = "Pointer Position: (" + e.PointerPos.X.ToString() + "," + e.PointerPos.Y.ToString() + ")"; //Let's not do StringBuilder for this one.
                toolStripMousePos.Text = pointerStatus;                                                                           //Update the status bar
            }
        }
コード例 #10
0
        private void GlobalMouseHook_OnMouseWheelScroll(object sender, GlobalMouseEventArgs e)
        {
            //We shouldn't make a log for this if the checkNoScrollWheel checkbox is checked.
            if (!checkNoLogScrollWheel.Checked)
            {
                StringBuilder logText = new StringBuilder("Mouse: Scroll Wheel has been rotated "); //Let's start buliding the log text.

                logText.Append(e.wheelRotation.ToString());                                         //Append the rotation of the scroll wheel.
                logText.Append(" " + Misc.MousePositionToString(e.PointerPos));                     //Append the position of the mouse pointer on the screen as the event occured.

                listLog.Items.Add(logText.ToString());                                              //Build the log text and it to the log.
            }

            //if checkNoScroll checkbox is checked, disable our scroll wheel by letting the system know that we are handling scroll events.
            if (checkNoScroll.Checked)
            {
                e.Handled = true;
                return;
            }
        }
コード例 #11
0
 private static void GlobalMouseHook_OnButtonDown(object sender, GlobalMouseEventArgs e)
 {
     Console.WriteLine("Button Down: " + e.Button.ToString());
 }