Beispiel #1
0
 internal void OnMouseDown(MouseEventArgs e)
 {
     if (MouseDown != null)
     {
         MouseDown.Invoke(this, e);
     }
 }
Beispiel #2
0
        private IntPtr MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                MSLLHOOKSTRUCT mouseHookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
                if (wParam.ToInt32() == WM_LBUTTONDOWN)
                {
                    if (MouseDown != null)
                    {
                        MouseDown.Invoke(null, new System.Drawing.Point(mouseHookStruct.pt.x, mouseHookStruct.pt.y));
                    }

                    return(new IntPtr(-1));
                }

                if (wParam.ToInt32() == WM_MOUSEWHEEL)
                {
                    if (MouseWheel != null)
                    {
                        MouseDevice mouseDev = InputManager.Current.PrimaryMouseDevice;
                        MouseWheel.Invoke(null, new MouseWheelEventArgs(mouseDev, Environment.TickCount, (int)mouseHookStruct.mouseData >> 16));
                    }
                }
            }

            return(CallNextHookEx(_mouseHookHandle, nCode, wParam, lParam));
        }
Beispiel #3
0
 public void OnPointerDown(PointerEventData eventData)
 {
     if (MouseDown != null)
     {
         MouseDown.Invoke(this, eventData);
     }
 }
 private void listView1_MouseDown(object sender, MouseEventArgs e)
 {
     if (MouseDown != null)
     {
         MouseDown.Invoke(sender, e);
     }
 }
Beispiel #5
0
 public DisplayPanelBox(PictureBox pBox, VScrollBar vs, HScrollBar hs)
 {
     pictureBox            = pBox;
     pictureBox.MouseDown += (s, e) =>
     {
         clicking = true;
         MouseDown.Invoke(e);
     };
     pictureBox.MouseMove += (s, e) =>
     {
         if (clicking)
         {
             MouseDrag.Invoke(e);
         }
         else
         {
             MouseMove.Invoke(e);
         }
     };
     pictureBox.MouseUp += (s, e) =>
     {
         clicking = false;
         MouseUp.Invoke(e);
     };
     vScroll = vs;
     hScroll = hs;
 }
Beispiel #6
0
 public void Invoke(string EventName, Game CurrentGame, EventArguments Args)
 {
     if (EventName == "Closing")
     {
         Closing.Invoke(CurrentGame, Args);
     }
     if (EventName == "KeyDown")
     {
         KeyDown.Invoke(CurrentGame, Args);
     }
     if (EventName == "KeyUp")
     {
         KeyUp.Invoke(CurrentGame, Args);
     }
     if (EventName == "KeyPress")
     {
         KeyPress.Invoke(CurrentGame, Args);
     }
     if (EventName == "Load")
     {
         Load.Invoke(CurrentGame, Args);
     }
     if (EventName == "MouseDown")
     {
         MouseDown.Invoke(CurrentGame, Args);
     }
     if (EventName == "MouseUp")
     {
         MouseUp.Invoke(CurrentGame, Args);
     }
     if (EventName == "MouseClick")
     {
         MouseClick.Invoke(CurrentGame, Args);
     }
     if (EventName == "MouseMove")
     {
         MouseMove.Invoke(CurrentGame, Args);
     }
     if (EventName == "MouseWheel")
     {
         MouseWheel.Invoke(CurrentGame, Args);
     }
     if (EventName == "RenderFrame")
     {
         RenderFrame.Invoke(CurrentGame, Args);
     }
     if (EventName == "Resize")
     {
         Resize.Invoke(CurrentGame, Args);
     }
     if (EventName == "TimerTick")
     {
         TimerTick.Invoke(CurrentGame, Args);
     }
 }
Beispiel #7
0
 /// <summary>
 /// Receives all MouseDown events, and checks if control is focused and
 /// should receive event.
 /// </summary>
 /// <param name="args">Mouse event arguments.</param>
 protected virtual void MouseDownIntercept(MouseEventArgs args)
 {
     // Check coordinates as well because modal mode messes up the
     // MouseDown event.
     if (this.guiManager.GetFocus() == this &&
         CheckCoordinates(args.Position.X, args.Position.Y)
         )
     {
         MouseDown.Invoke(args);
     }
 }
Beispiel #8
0
        private void setKeyDown(MouseButton key)
        {
            if (key == MouseButton.NONE)
            {
                return;
            }

            buttons.Put(key, true);

            if (MouseDown != null)
            {
                MouseDown.Invoke(this, new MouseEvent(this, key));
            }
        }
 public void Update()
 {
     if (Input.GetMouseButtonUp(0))
     {
         MouseUp.Invoke();
     }
     if (Input.GetMouseButtonDown(0))
     {
         MouseClick.Invoke();
     }
     if (Input.GetMouseButton(0))
     {
         MouseDown.Invoke();
     }
     OnUpdate.Invoke();
 }
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_PASTE)
            {
                if (Clipboard.ContainsText())
                {
                    Paste.Invoke(this, new EventArgs());
                }
                return;
            }

            if (m.Msg == WM_LBUTTONDOWN)
            {
                MouseDown.Invoke(this, new EventArgs());
            }

            base.WndProc(ref m);
        }
Beispiel #11
0
        } // UpdateMouse

        private void UpdateButtons()
        {

            MouseEventArgs e = new MouseEventArgs();

            foreach (InputMouseButton btn in mouseButtons)
            {
                ButtonState bs;

                if      (btn.Button == MouseButton.Left)     bs = Mouse.State.LeftButton;
                else if (btn.Button == MouseButton.Right)    bs = Mouse.State.RightButton;
                else if (btn.Button == MouseButton.Middle)   bs = Mouse.State.MiddleButton;
                else if (btn.Button == MouseButton.XButton1) bs = Mouse.State.XButton1;
                else if (btn.Button == MouseButton.XButton2) bs = Mouse.State.XButton2;
                else continue;

                bool pressed = (bs == ButtonState.Pressed); // The current state

                if (pressed && !btn.Pressed) // If is pressed and the last frame wasn't pressed.
                {
                    btn.Pressed = true;
                    BuildMouseEvent(btn.Button, ref e);

                    if (MouseDown != null) MouseDown.Invoke(this, e);
                    if (MousePress != null) MousePress.Invoke(this, e);
                }
                else if (!pressed && btn.Pressed) // If isn't pressed and the last frame was pressed.
                {
                    btn.Pressed = false;
                    BuildMouseEvent(btn.Button, ref e);

                    if (MouseUp != null) MouseUp.Invoke(this, e);
                }
                else if (pressed && btn.Pressed) // If is pressed and was pressed.
                {
                    e.Button = btn.Button;
                    BuildMouseEvent(btn.Button, ref e);
                    if (MousePress != null) MousePress.Invoke(this, e);
                }
            }
        } // UpdateButtons
Beispiel #12
0
        public virtual void OnMouseDown(MouseEventArgs e)
        {
            if (!_enabled)
            {
                return;
            }

            Activate();

            TrySort();

            if (_movable)
            {
                Moving     = true;
                _movePoint = CMain.MPoint.Subtract(Location);
            }

            if (MouseDown != null)
            {
                MouseDown.Invoke(this, e);
            }
        }
Beispiel #13
0
        public virtual void OnMouseDown(MouseEventArgs e)
        {
            if (!_Enabled)
            {
                return;
            }

            ActiveControl = this;

            TrySort();

            if (_Movable)
            {
                Moving    = true;
                MovePoint = Functions.PointS(e.Location, Location);
            }

            if (MouseDown != null)
            {
                MouseDown.Invoke(this, e);
            }
        }
Beispiel #14
0
 private void OnMouseDown()
 {
     MouseDown.Invoke();
 }
Beispiel #15
0
 //down
 protected void RaiseMouseDown(object sender, MouseArg e)
 {
     MouseDown?.Invoke(sender, e);
 }
Beispiel #16
0
 public void ProcessMouseDown(MouseArgs args)
 {
     MouseDown?.Invoke(this, args);
 }
Beispiel #17
0
 /// <summary>
 /// Invokes the MouseDown event.
 /// </summary>
 /// <param name="v">Location of the mouse.</param>
 /// <param name="b">The current state of the mouse buttons.</param>
 internal void DoMouseDown(Vec2 v, MouseButtons b)
 {
     MouseDown.Invoke(v, b);
 }
        ////////////////////////////////////////////////////////////////////////////

        ////////////////////////////////////////////////////////////////////////////
        private void UpdateButtons(MouseState state, GameTime gameTime)
        {
#if (!XBOX && !XBOX_FAKE)
            MouseEventArgs e = new MouseEventArgs();

            foreach (InputMouseButton btn in mouseButtons)
            {
                ButtonState bs = ButtonState.Released;

                if (btn.Button == MouseButton.Left)
                {
                    bs = state.LeftButton;
                }
                else if (btn.Button == MouseButton.Right)
                {
                    bs = state.RightButton;
                }
                else if (btn.Button == MouseButton.Middle)
                {
                    bs = state.MiddleButton;
                }
                else if (btn.Button == MouseButton.XButton1)
                {
                    bs = state.XButton1;
                }
                else if (btn.Button == MouseButton.XButton2)
                {
                    bs = state.XButton2;
                }
                else
                {
                    continue;
                }

                bool pressed = (bs == ButtonState.Pressed);
                if (pressed)
                {
                    double ms = gameTime.ElapsedGameTime.TotalMilliseconds;
                    if (pressed)
                    {
                        btn.Countdown -= ms;
                    }
                }

                if ((pressed) && (!btn.Pressed))
                {
                    btn.Pressed = true;
                    BuildMouseEvent(state, btn.Button, ref e);

                    if (MouseDown != null)
                    {
                        MouseDown.Invoke(this, e);
                    }
                    if (MousePress != null)
                    {
                        MousePress.Invoke(this, e);
                    }
                }
                else if ((!pressed) && (btn.Pressed))
                {
                    btn.Pressed   = false;
                    btn.Countdown = RepeatDelay;
                    BuildMouseEvent(state, btn.Button, ref e);

                    if (MouseUp != null)
                    {
                        MouseUp.Invoke(this, e);
                    }
                }
                else if (btn.Pressed && btn.Countdown < 0)
                {
                    e.Button      = btn.Button;
                    btn.Countdown = RepeatRate;
                    BuildMouseEvent(state, btn.Button, ref e);

                    if (MousePress != null)
                    {
                        MousePress.Invoke(this, e);
                    }
                }
            }
#endif
        }
Beispiel #19
0
        /// <param name="gameTime">Snapshot of the application's timing values.</param>
        /// <param name="state">Current state of the mouse device.</param>
        /// <summary>
        /// Updates the state of the Mouse buttons.
        /// </summary>
        private void UpdateButtons(MouseState state, GameTime gameTime)
        {
#if (!XBOX && !XBOX_FAKE)
            var e = new MouseEventArgs();


// Update the state of the buttons in the mouse button list.
            foreach (var btn in mouseButtons)
            {
// Current button state of the current gamepad button.
                var bs = ButtonState.Released;

                if (btn.Button == MouseButton.Left)
                {
                    bs = state.LeftButton;
                }
                else if (btn.Button == MouseButton.Right)
                {
                    bs = state.RightButton;
                }
                else if (btn.Button == MouseButton.Middle)
                {
                    bs = state.MiddleButton;
                }
                else if (btn.Button == MouseButton.XButton1)
                {
                    bs = state.XButton1;
                }
                else if (btn.Button == MouseButton.XButton2)
                {
                    bs = state.XButton2;
                }
                else
                {
                    continue;
                }

// Current state button pressed?
                var pressed = (bs == ButtonState.Pressed);
                if (pressed)
                {
// Update the repeat delay timer for the associated button.
                    var ms = gameTime.ElapsedGameTime.TotalMilliseconds;
                    if (pressed)
                    {
                        btn.Countdown -= ms;
                    }
                }

// Button was just pressed?
                if ((pressed) && (!btn.Pressed))
                {
// "Press" the associated button.
                    btn.Pressed = true;
                    BuildMouseEvent(state, btn.Button, ref e);

// Fire the MouseDown and MousePress events.
                    if (MouseDown != null)
                    {
                        MouseDown.Invoke(this, e);
                    }
// Fire the repeat MousePress event.
                }
// Button was just released?
                else if ((!pressed) && (btn.Pressed))
                {
// "Release" the associated button and reset the repeat delay timer.
                    btn.Pressed   = false;
                    btn.Countdown = RepeatDelay;
                    BuildMouseEvent(state, btn.Button, ref e);
// Fire the MouseUp event.
                    if (MouseUp != null)
                    {
                        MouseUp.Invoke(this, e);
                    }
                }
// Button is held down and it's time to fire a repeat press event?
                else if (btn.Pressed && btn.Countdown < 0)
                {
// Update event args and reset timer.
                    e.Button      = btn.Button;
                    btn.Countdown = RepeatRate;
                    BuildMouseEvent(state, btn.Button, ref e);

// Fire the repeat MousePress event.
                    if (MousePress != null)
                    {
                        MousePress.Invoke(this, e);
                    }
                }
            }
#endif
        }
Beispiel #20
0
 /// <summary>
 /// Raise the event <see cref="MouseDown"/>.
 /// </summary>
 protected virtual void OnMouseDown(Point location, MouseButton buttons)
 {
     MouseDown?.Invoke(this, new NativeWindowMouseEventArgs(_DeviceContext, _RenderContext, location, buttons));
 }
Beispiel #21
0
        /// <summary>
        /// Goes through each key checking its state compared to the last
        /// frame, triggering events if necessary. Updates the current mouse
        /// state and triggers events if necessary.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            #region Update Keyboard
            // Create the Arguments class and fill in with the modifier data
            KeyEventArgs keyEvent = new KeyEventArgs();

            foreach (Keys key in Keyboard.GetState().GetPressedKeys())
            {
                if (key == Keys.LeftAlt || key == Keys.RightAlt)
                {
                    keyEvent.Alt = true;
                }
                else if (key == Keys.LeftShift || key == Keys.RightShift)
                {
                    keyEvent.Shift = true;
                }
                else if (key == Keys.LeftControl || key == Keys.RightControl)
                {
                    keyEvent.Control = true;
                }
            }

            // Loop through our keys
            foreach (InputKey key in this.keys)
            {
                // If they are any of the modifier keys, skip them
                if (key.Key == Keys.LeftAlt || key.Key == Keys.RightAlt ||
                    key.Key == Keys.LeftShift || key.Key == Keys.RightShift ||
                    key.Key == Keys.LeftControl || key.Key == Keys.RightControl
                    )
                {
                    continue;
                }

                // Check if the key was pressed
                bool pressed = Keyboard.GetState().IsKeyDown(key.Key);

                // If it was, decrement the countdown for that key
                if (pressed)
                {
                    key.Countdown -= gameTime.ElapsedRealTime.Milliseconds;
                }

                if ((pressed) && (!key.Pressed)) // If it is pressed, but wasn't before...
                {
                    // Set some flags and invoke the KeyDown event
                    key.Pressed  = true;
                    keyEvent.Key = key.Key;

                    if (KeyDown != null)
                    {
                        KeyDown.Invoke(keyEvent);
                    }
                }
                else if ((!pressed) && (key.Pressed)) // If it isn't pressed, but was before...
                {
                    // Set some flags, reset the countdown
                    key.Pressed   = false;
                    key.Countdown = RepeatDelay;
                    keyEvent.Key  = key.Key;

                    // Invoke the Key Up event
                    if (KeyUp != null)
                    {
                        KeyUp.Invoke(keyEvent);
                    }
                }

                // If the Key's Countdown has zeroed out, reset it, and make
                // sure that KeyDown fires again
                if (key.Countdown < 0)
                {
                    keyEvent.Key = key.Key;

                    if (KeyDown != null)
                    {
                        KeyDown.Invoke(keyEvent);
                    }

                    key.Countdown = RepeatRate;
                }
            }
            #endregion

            #region Update Mouse
            MouseState mouseState = Mouse.GetState();

            // Check for mouse move event
            if ((mouseState.X != this.currentMouseState.X) || (mouseState.Y != this.currentMouseState.Y))
            {
                if (MouseMove != null)
                {
                    MouseEventArgs mouseEvent = new MouseEventArgs();
                    mouseEvent.State  = mouseState;
                    mouseEvent.Button = MouseButtons.None;

                    // Cap mouse position to the window boundaries
                    mouseEvent.Position = new Point(mouseState.X, mouseState.Y);
                    if (mouseEvent.Position.X < 0)
                    {
                        mouseEvent.Position.X = 0;
                    }
                    if (mouseEvent.Position.Y < 0)
                    {
                        mouseEvent.Position.Y = 0;
                    }

                    Rectangle bounds = this.Game.Window.ClientBounds;

                    if (mouseEvent.Position.X > bounds.Width)
                    {
                        mouseEvent.Position.X = bounds.Width;
                    }
                    if (mouseEvent.Position.Y > bounds.Height)
                    {
                        mouseEvent.Position.Y = bounds.Height;
                    }


                    MouseMove.Invoke(mouseEvent);
                }
            }

            if (mouseState.LeftButton != currentMouseState.LeftButton)
            {
                if ((MouseUp != null) || (MouseDown != null))
                {
                    MouseEventArgs mouseEvent = new MouseEventArgs();
                    mouseEvent.State    = mouseState;
                    mouseEvent.Position = new Point(mouseState.X, mouseState.Y);
                    mouseEvent.Button   = MouseButtons.Left;

                    if (mouseState.LeftButton == ButtonState.Released)
                    {
                        if (MouseUp != null)
                        {
                            MouseUp.Invoke(mouseEvent);
                        }
                    }
                    else
                    {
                        if (MouseDown != null)
                        {
                            // Must request focus first, to prevent mousedown
                            // event from being swallowed up
                            if (RequestingFocus != null)
                            {
                                RequestingFocus.Invoke(mouseEvent);
                            }

                            MouseDown.Invoke(mouseEvent);
                        }
                    }
                }
            }

            if (mouseState.RightButton != currentMouseState.RightButton)
            {
                if ((MouseUp != null) || (MouseDown != null))
                {
                    MouseEventArgs mouseEvent = new MouseEventArgs();
                    mouseEvent.State    = mouseState;
                    mouseEvent.Position = new Point(mouseState.X, mouseState.Y);
                    mouseEvent.Button   = MouseButtons.Right;

                    if (mouseState.RightButton == ButtonState.Released)
                    {
                        if (MouseUp != null)
                        {
                            MouseUp.Invoke(mouseEvent);
                        }
                    }
                    else
                    {
                        if (MouseDown != null)
                        {
                            MouseDown.Invoke(mouseEvent);
                        }
                    }
                }
            }

            // Update mouse state
            this.currentMouseState = mouseState;
            #endregion

            base.Update(gameTime);
        }
 protected virtual void OnMouseDown(MouseButton button) => MouseDown?.Invoke(button);
Beispiel #23
0
 /// <summary>
 /// Raises the MouseDown event. Override this method to add code to handle when a mouse button is pressed
 /// </summary>
 /// <param name="e">InputEventCM for the MouseDown event</param>
 private void invokeMouseDown(InputEventMouse e)
 {
     MouseDown?.Invoke(e);
 }
Beispiel #24
0
 private void pbMyPictureBox_MouseDown(object sender, MouseEventArgs e)
 {
     MouseDown?.Invoke(this, e);
 }
Beispiel #25
0
        private IntPtr MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            Hook.MSLLHOOKSTRUCT    hs = (Hook.MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Hook.MSLLHOOKSTRUCT));
            Message.WindowsMessage wm = (Message.WindowsMessage)wParam;
            if (nCode >= 0)
            {
                Keyboard.VirtualKeyStates key;
                switch (wm)
                {
                case Message.WindowsMessage.LBUTTONDOWN:
                case Message.WindowsMessage.NCLBUTTONDOWN:
                case Message.WindowsMessage.LBUTTONUP:
                case Message.WindowsMessage.NCLBUTTONUP:
                    key = Keyboard.VirtualKeyStates.LButton;
                    break;

                case Message.WindowsMessage.RBUTTONDOWN:
                case Message.WindowsMessage.NCRBUTTONDOWN:
                case Message.WindowsMessage.RBUTTONUP:
                case Message.WindowsMessage.NCRBUTTONUP:
                    key = Keyboard.VirtualKeyStates.RButton;
                    break;

                case Message.WindowsMessage.MBUTTONDOWN:
                case Message.WindowsMessage.NCMBUTTONDOWN:
                case Message.WindowsMessage.MBUTTONUP:
                case Message.WindowsMessage.NCMBUTTONUP:
                    key = Keyboard.VirtualKeyStates.MButton;
                    break;

                case Message.WindowsMessage.XBUTTONDOWN:
                case Message.WindowsMessage.NCXBUTTONDOWN:
                case Message.WindowsMessage.XBUTTONUP:
                case Message.WindowsMessage.NCXBUTTONUP:
                    key = (hs.mouseData & 0x10000) != 0 ? Keyboard.VirtualKeyStates.XButton1 : Keyboard.VirtualKeyStates.XButton2;
                    break;

                default:
                    key = Keyboard.VirtualKeyStates.None;
                    break;
                }
                MouseState.MouseStatus status;
                switch (wm)
                {
                case Message.WindowsMessage.LBUTTONDOWN:
                case Message.WindowsMessage.NCLBUTTONDOWN:
                case Message.WindowsMessage.RBUTTONDOWN:
                case Message.WindowsMessage.NCRBUTTONDOWN:
                case Message.WindowsMessage.MBUTTONDOWN:
                case Message.WindowsMessage.NCMBUTTONDOWN:
                case Message.WindowsMessage.XBUTTONDOWN:
                case Message.WindowsMessage.NCXBUTTONDOWN:
                    status = MouseState.MouseStatus.Down;
                    break;

                case Message.WindowsMessage.LBUTTONUP:
                case Message.WindowsMessage.NCLBUTTONUP:
                case Message.WindowsMessage.RBUTTONUP:
                case Message.WindowsMessage.NCRBUTTONUP:
                case Message.WindowsMessage.MBUTTONUP:
                case Message.WindowsMessage.NCMBUTTONUP:
                case Message.WindowsMessage.XBUTTONUP:
                case Message.WindowsMessage.NCXBUTTONUP:
                    status = MouseState.MouseStatus.Up;
                    break;

                case Message.WindowsMessage.MOUSEWHEEL:
                case Message.WindowsMessage.MOUSEHWHEEL:
                    status = MouseState.MouseStatus.Wheel;
                    break;

                case Message.WindowsMessage.MOUSEMOVE:
                case Message.WindowsMessage.NCMOUSEMOVE:
                    status = MouseState.MouseStatus.Move;
                    break;

                default:
                    status = MouseState.MouseStatus.None;
                    break;
                }
                int wheel;
                int hWheel;
                switch (wm)
                {
                case Message.WindowsMessage.MOUSEWHEEL:
                    wheel  = (short)(hs.mouseData >> 16);
                    hWheel = 0;
                    break;

                case Message.WindowsMessage.MOUSEHWHEEL:
                    wheel  = 0;
                    hWheel = (short)(hs.mouseData >> 16);
                    break;

                default:
                    wheel  = 0;
                    hWheel = 0;
                    break;
                }
                MouseState ms = MouseState.CreateCurrent(key, status, hs.x, hs.y, wheel, hWheel, TimeSpan.FromMilliseconds(hs.time));
                switch (ms.Status)
                {
                case MouseState.MouseStatus.Down:
                    MouseAny?.Invoke(this, ms);
                    MouseDown?.Invoke(this, ms);
                    break;

                case MouseState.MouseStatus.Up:
                    MouseAny?.Invoke(this, ms);
                    MouseUp?.Invoke(this, ms);
                    break;

                case MouseState.MouseStatus.Wheel:
                    MouseAny?.Invoke(this, ms);
                    MouseWheel?.Invoke(this, ms);
                    break;

                case MouseState.MouseStatus.Move:
                    MouseAny?.Invoke(this, ms);
                    MouseMove?.Invoke(this, ms);
                    break;

                default:
                    MouseAny?.Invoke(this, ms);
                    break;
                }
                if (CallNextHook is null || CallNextHook(this, ms))
                {
                    return(Hook.CallNextHookEx(_mHHook, nCode, wParam, lParam));
                }
                else
                {
                    return(_mHHook);
                }
            }
Beispiel #26
0
 /// <summary>
 /// Allows for inheriting tools to control OnMouseDown.
 /// </summary>
 /// <param name="e">A GeoMouseArgs parameter.</param>
 protected virtual void OnMouseDown(GeoMouseArgs e)
 {
     MouseDown?.Invoke(this, e);
 }
Beispiel #27
0
        protected override bool HookCallback(IntPtr wParam, IntPtr lParam)
        {
            var mouseHookStruct = (MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseLLHookStruct));

            MouseButtons button     = MouseButtons.None;
            Keys         keyCode    = Keys.None;
            short        mouseDelta = 0;
            int          clickCount = 0;

            bool isMouseButtonDown = false;
            bool isMouseButtonUp   = false;

            switch ((Messages)wParam)
            {
            case Messages.WM_LBUTTONDOWN:
            case Messages.WM_LBUTTONUP:
            case Messages.WM_LBUTTONDBLCLK:
                button  = MouseButtons.Left;
                keyCode = Keys.LButton;
                break;

            case Messages.WM_RBUTTONDOWN:
            case Messages.WM_RBUTTONUP:
            case Messages.WM_RBUTTONDBLCLK:
                button  = MouseButtons.Right;
                keyCode = Keys.RButton;
                break;

            case Messages.WM_MBUTTONDOWN:
            case Messages.WM_MBUTTONUP:
            case Messages.WM_MBUTTONDBLCLK:
                button  = MouseButtons.Middle;
                keyCode = Keys.MButton;
                break;

            case Messages.WM_XBUTTONDOWN:
            case Messages.WM_XBUTTONUP:
            case Messages.WM_XBUTTONDBLCLK:
                if (mouseHookStruct.MouseData == 1)
                {
                    button  = MouseButtons.XButton1;
                    keyCode = Keys.XButton1;
                }
                else
                {
                    button  = MouseButtons.XButton2;
                    keyCode = Keys.XButton2;
                }
                break;
            }


            switch ((Messages)wParam)
            {
            case Messages.WM_MOUSEWHEEL:
                mouseDelta = mouseHookStruct.MouseData;
                if (mouseDelta > 0)
                {
                    keyCode = (Keys)KeysEx.WheelUp;
                }
                if (mouseDelta < 0)
                {
                    keyCode = (Keys)KeysEx.WheelDown;
                }
                break;

            case Messages.WM_MOUSEHWHEEL:
                //mouseDelta = mouseHookStruct.MouseData;
                break;

            case Messages.WM_LBUTTONDOWN:
            case Messages.WM_RBUTTONDOWN:
            case Messages.WM_MBUTTONDOWN:
            case Messages.WM_XBUTTONDOWN:
                clickCount        = 1;
                isMouseButtonDown = true;
                break;

            case Messages.WM_LBUTTONUP:
            case Messages.WM_RBUTTONUP:
            case Messages.WM_MBUTTONUP:
            case Messages.WM_XBUTTONUP:
                clickCount      = 1;
                isMouseButtonUp = true;
                break;

            case Messages.WM_LBUTTONDBLCLK:
            case Messages.WM_RBUTTONDBLCLK:
            case Messages.WM_MBUTTONDBLCLK:
            case Messages.WM_XBUTTONDBLCLK:
                clickCount = 2;
                break;
            }

            var e = new MouseEventExtArgs(
                button,
                keyCode,
                clickCount,
                mouseHookStruct.Point.X,
                mouseHookStruct.Point.Y,
                mouseDelta);

            if (MouseDown != null && isMouseButtonDown)
            {
                MouseDown.Invoke(null, e);
            }

            if (MouseUp != null && isMouseButtonUp)
            {
                MouseUp.Invoke(null, e);
            }

            if (MouseWheel != null && mouseDelta != 0)
            {
                MouseWheel.Invoke(null, e);
            }

            if (MouseMove != null && !_oldPoint.Equals(mouseHookStruct.Point))
            {
                MouseMove.Invoke(null, e);
            }

            _oldPoint = mouseHookStruct.Point;
            return(e.Handled);
        }
Beispiel #28
0
 internal void InvokeMouseDown(ScreenEventArgs args) => MouseDown?.Invoke(this, args);
Beispiel #29
0
        private void mouseHook_Callback(int nCode, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            //Marshall the data from callback.
            MouseLLHookStruct mouseHookStruct =
                (MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseLLHookStruct));

            //detect button clicked
            MouseButtons button     = MouseButtons.None;
            short        mouseDelta = 0;
            bool         mouseDown  = false;
            bool         mouseUp    = false;

            switch ((int)wParam)
            {
            case WM_LBUTTONDOWN:
                mouseDown = true;
                button    = MouseButtons.Left;
                break;

            case WM_LBUTTONUP:
                mouseUp = true;
                button  = MouseButtons.Left;
                break;

            case WM_RBUTTONDOWN:
                mouseDown = true;
                button    = MouseButtons.Right;
                break;

            case WM_RBUTTONUP:
                mouseUp = true;
                button  = MouseButtons.Right;
                break;

            case WM_MBUTTONDOWN:
                mouseDown = true;
                button    = MouseButtons.Middle;
                break;

            case WM_MBUTTONUP:
                mouseUp = true;
                button  = MouseButtons.Middle;
                break;

            case WM_MOUSEWHEEL:
                //If the message is WM_MOUSEWHEEL, the high-order word of MouseData member is the wheel delta.
                //One wheel click is defined as WHEEL_DELTA, which is 120.
                //(value >> 16) & 0xffff; retrieves the high-order word from the given 32-bit value
                mouseDelta = (short)((mouseHookStruct.MouseData >> 16) & 0xffff);
                break;

            case WM_XBUTTONDOWN:
                mouseDown = true;
                switch (mouseHookStruct.MouseData >> 16)
                {
                case XBUTTON1:
                    button = MouseButtons.XButton1;
                    break;

                case XBUTTON2:
                    button = MouseButtons.XButton2;
                    break;
                }
                break;

            case WM_XBUTTONUP:
                mouseUp = true;
                switch (mouseHookStruct.MouseData >> 16)
                {
                case XBUTTON1:
                    button = MouseButtons.XButton1;
                    break;

                case XBUTTON2:
                    button = MouseButtons.XButton2;
                    break;
                }
                break;
            }

            //generate event
            MouseEventExtArgs e = new MouseEventExtArgs(
                button,
                mouseUp || mouseDown ? 1 : 0,
                mouseHookStruct.Point.X,
                mouseHookStruct.Point.Y,
                mouseDelta);

            //Mouse down
            if (MouseDown != null && mouseDown)
            {
                MouseDown.Invoke(null, e);
            }

            //If someone listens to click and a click is heppened
            if (MouseClick != null && mouseDown)
            {
                MouseClick.Invoke(null, e);
            }

            //Mouse up
            if (MouseUp != null && mouseUp)
            {
                MouseUp.Invoke(null, e);
            }

            //Wheel was moved
            if (MouseWheel != null && mouseDelta != 0)
            {
                MouseWheel.Invoke(null, e);
            }

            handled = handled || e.Handled;

            //If someone listens to move and there was a change in coordinates raise move event
            if ((MouseMove != null) && (mOldX != mouseHookStruct.Point.X || mOldY != mouseHookStruct.Point.Y))
            {
                mOldX = mouseHookStruct.Point.X;
                mOldY = mouseHookStruct.Point.Y;

                MouseMove.Invoke(null, e);
                handled = handled || (e.Handled && (int)wParam == WM_MOUSEMOVE);
            }
        }
Beispiel #30
0
 internal void InvokeMouseDown(S sender, T state, UIMouseDownEventArgs e)
 {
     MouseDown.Invoke(new SenderInfo(sender, state), e);
 }