示例#1
0
        /// <summary>
        /// Callback that is called after the mouse hook has been installed when the thread recieves a mouse message
        /// </summary>
        /// <param name="nCode">A code that the hook procedure uses to determine how to process the message</param>
        /// <param name="wParam">The identifier of the mouse message</param>
        /// <param name="lParam">A pointer to a MOUSEHOOKSTRUCT structure</param>
        /// <returns>Value returned by CallNextHookEx</returns>
        public int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0)
            {
                return(NM.CallNextHookEx(m_hMouseHook, nCode, wParam, lParam));
            }
            else
            {
                NM.MouseHookStruct MyMouseHookStruct = (NM.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(NM.MouseHookStruct));

                if (MyMouseHookStruct.hwnd == m_HookWindow)
                {
                    if (nCode == NM.HC_ACTION)
                    {
                        switch (wParam.ToInt32())
                        {
                        case NM.WM_LBUTTONDOWN:
                            DebugLogging.WriteLog("Left Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_LBUTTONDOWN = true;
                            break;

                        case NM.WM_NCLBUTTONDOWN:
                            DebugLogging.WriteLog("NCLeft Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_LBUTTONDOWN = true;
                            break;

                        case NM.WM_LBUTTONUP:
                            DebugLogging.WriteLog("Left Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_LBUTTONUP = true;
                            break;

                        case NM.WM_NCLBUTTONUP:
                            DebugLogging.WriteLog("NCLeft Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_LBUTTONUP = true;
                            break;

                        case NM.WM_LBUTTONDBLCLK:
                            DebugLogging.WriteLog("Left Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_LBUTTONDBLCLK = true;
                            break;

                        case NM.WM_NCLBUTTONDBLCLK:
                            DebugLogging.WriteLog("NCLeft Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_LBUTTONDBLCLK = true;
                            break;

                        case NM.WM_RBUTTONDOWN:
                            DebugLogging.WriteLog("Right Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_RBUTTONDOWN = true;
                            break;

                        case NM.WM_NCRBUTTONDOWN:
                            DebugLogging.WriteLog("NCRight Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_RBUTTONDOWN = true;
                            break;

                        case NM.WM_RBUTTONUP:
                            DebugLogging.WriteLog("Right Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_RBUTTONUP = true;
                            break;

                        case NM.WM_NCRBUTTONUP:
                            DebugLogging.WriteLog("NCRight Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_RBUTTONUP = true;
                            break;

                        case NM.WM_RBUTTONDBLCLK:
                            DebugLogging.WriteLog("Right Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_RBUTTONDBLCLK = true;
                            break;

                        case NM.WM_NCRBUTTONDBLCLK:
                            DebugLogging.WriteLog("NCRight Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_RBUTTONDBLCLK = true;
                            break;

                        case NM.WM_MBUTTONDOWN:
                            DebugLogging.WriteLog("Middle Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_MBUTTONDOWN = true;
                            break;

                        case NM.WM_NCMBUTTONDOWN:
                            DebugLogging.WriteLog("NCMiddle Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_MBUTTONDOWN = true;
                            break;

                        case NM.WM_MBUTTONUP:
                            DebugLogging.WriteLog("Middle Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            break;

                        case NM.WM_NCMBUTTONUP:
                            DebugLogging.WriteLog("NCMiddle Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_MBUTTONUP = true;
                            break;

                        case NM.WM_MBUTTONDBLCLK:
                            DebugLogging.WriteLog("Middle Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_MBUTTONDBLCLK = true;
                            break;

                        case NM.WM_NCMBUTTONDBLCLK:
                            DebugLogging.WriteLog("NCMiddle Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_MBUTTONDBLCLK = true;
                            break;
                        }
                    }
                }
                return(NM.CallNextHookEx(m_hMouseHook, nCode, wParam, lParam));
            }
        }
示例#2
0
        /// <summary>
        /// Callback that is called after the mouse hook has been installed when the thread recieves a mouse message
        /// </summary>
        /// <param name="nCode">A code that the hook procedure uses to determine how to process the message</param>
        /// <param name="wParam">The identifier of the mouse message</param>
        /// <param name="lParam">A pointer to a MOUSEHOOKSTRUCT structure</param>
        /// <returns>Value returned by CallNextHookEx</returns>
        public int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0)
            {
                return(NM.CallNextHookEx(m_hMouseHook, nCode, wParam, lParam));
            }
            else
            {
                NM.MouseHookStruct MyMouseHookStruct = (NM.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(NM.MouseHookStruct));

                //Check if the window or its parent recieved a mouse message (we check for a parent as they have a bad habit of eating some clicks)
                //if (MyMouseHookStruct.hwnd == m_HookWindow || NM.IsChild(MyMouseHookStruct.hwnd, m_HookWindow))
                //{
                if (nCode == NM.HC_ACTION)
                {
                    switch (wParam.ToInt32())
                    {
                    case NM.WM_MOUSEMOVE:
                    case NM.WM_NCMOUSEMOVE:
                        m_WM_MouseMove_ScreenX = MyMouseHookStruct.pt.x;
                        m_WM_MouseMove_ScreenY = MyMouseHookStruct.pt.y;
                        break;

                    case NM.WM_LBUTTONDOWN:
                        DebugLogging.WriteLog("Left Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_LBUTTONDOWN = true;
                        break;

                    case NM.WM_NCLBUTTONDOWN:
                        DebugLogging.WriteLog("NCLeft Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_LBUTTONDOWN = true;
                        break;

                    case NM.WM_LBUTTONUP:
                        DebugLogging.WriteLog("Left Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_LBUTTONUP = true;
                        break;

                    case NM.WM_NCLBUTTONUP:
                        DebugLogging.WriteLog("NCLeft Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_LBUTTONUP = true;
                        break;

                    case NM.WM_LBUTTONDBLCLK:
                        DebugLogging.WriteLog("Left Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_LBUTTONDBLCLK = true;
                        break;

                    case NM.WM_NCLBUTTONDBLCLK:
                        DebugLogging.WriteLog("NCLeft Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_LBUTTONDBLCLK = true;
                        break;

                    case NM.WM_RBUTTONDOWN:
                        DebugLogging.WriteLog("Right Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_RBUTTONDOWN = true;
                        break;

                    case NM.WM_NCRBUTTONDOWN:
                        DebugLogging.WriteLog("NCRight Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_RBUTTONDOWN = true;
                        break;

                    case NM.WM_RBUTTONUP:
                        DebugLogging.WriteLog("Right Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_RBUTTONUP = true;
                        break;

                    case NM.WM_NCRBUTTONUP:
                        DebugLogging.WriteLog("NCRight Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_RBUTTONUP = true;
                        break;

                    case NM.WM_RBUTTONDBLCLK:
                        DebugLogging.WriteLog("Right Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_RBUTTONDBLCLK = true;
                        break;

                    case NM.WM_NCRBUTTONDBLCLK:
                        DebugLogging.WriteLog("NCRight Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_RBUTTONDBLCLK = true;
                        break;

                    case NM.WM_MBUTTONDOWN:
                        DebugLogging.WriteLog("Middle Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_MBUTTONDOWN = true;
                        break;

                    case NM.WM_NCMBUTTONDOWN:
                        DebugLogging.WriteLog("NCMiddle Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_MBUTTONDOWN = true;
                        break;

                    case NM.WM_MBUTTONUP:
                        DebugLogging.WriteLog("Middle Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        break;

                    case NM.WM_NCMBUTTONUP:
                        DebugLogging.WriteLog("NCMiddle Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_MBUTTONUP = true;
                        break;

                    case NM.WM_MBUTTONDBLCLK:
                        DebugLogging.WriteLog("Middle Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_MBUTTONDBLCLK = true;
                        break;

                    case NM.WM_NCMBUTTONDBLCLK:
                        DebugLogging.WriteLog("NCMiddle Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_MBUTTONDBLCLK = true;
                        break;
                    }
                }
                //}
                return(NM.CallNextHookEx(m_hMouseHook, nCode, wParam, lParam));
            }
        }