Exemplo n.º 1
0
        private int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0)
            {
                return(Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam));
            }
            else
            {
                switch ((int)wParam)
                {
                case WM_LBUTTONDOWN:
                    MouseStateChanged?.Invoke(this, new MouseStateChangedEventArgs(1, true));
                    break;

                case WM_RBUTTONDOWN:
                    MouseStateChanged?.Invoke(this, new MouseStateChangedEventArgs(2, true));
                    break;

                case WM_MBUTTONDOWN:
                    MouseStateChanged?.Invoke(this, new MouseStateChangedEventArgs(3, true));
                    break;

                case WM_LBUTTONUP:
                    MouseStateChanged?.Invoke(this, new MouseStateChangedEventArgs(1, false));
                    break;

                case WM_RBUTTONUP:
                    MouseStateChanged?.Invoke(this, new MouseStateChangedEventArgs(2, false));
                    break;

                case WM_MBUTTONUP:
                    MouseStateChanged?.Invoke(this, new MouseStateChangedEventArgs(3, false));
                    break;
                }
                return(Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam));
            }
        }
Exemplo n.º 2
0
 /// <summary>Invokes the mouse state changed event.</summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnMouseStateChanged(MouseStateEventArgs e)
 {
     Invalidate();
     MouseStateChanged?.Invoke(e);
 }
Exemplo n.º 3
0
 /// <summary>Invokes the mouse state changed event.</summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The event args.</param>
 protected virtual void OnMouseStateChanged(object sender, MouseStateEventArgs e)
 {
     Invalidate();
     MouseStateChanged?.Invoke(sender, e);
 }