예제 #1
0
 static extern int CallNextHookEx(IntPtr idHook, int nCode, int wParam, ref Msllhookstruct lParam);
예제 #2
0
        private int hookProc(int nCode, int wParam, ref Msllhookstruct lParam)
        {
            Boolean boolNext = true;

            try
            {
                if (wParam != WM_MOUSEMOVE)
                {
                    //Console.WriteLine("WPARAM:  {0}",wParam.ToString("X"));
                    String msg = "";
                    if (wParam == WM_MOUSEWHEEL)
                    {
                        Delta = (int)(lParam.MouseData >> 16);
                        if (lParam.Location == pos_hidden)
                        {
                            boolMouseWheelMove = true;
                            if (Delta > 0)
                            {
                                msg = "Scroll up";
                            }
                            else if (Delta < 0)
                            {
                                msg = "Scroll down";
                            }
                        }
                    }
                    else if (wParam == WM_LBUTTONUP)
                    {
                        msg = "Left button up";
                    }
                    else if (wParam == WM_RBUTTONUP)
                    {
                        msg = "Right button up";
                    }
                    else if (wParam == WM_MBUTTONUP)
                    {
                        msg = "Middle button up";
                    }
                    else if (wParam == WM_LBUTTONDOWN)
                    {
                        msg = "Left button down";
                        if (lParam.Location == pos_hidden)
                        {
                            boolMouseDownLeft = true;
                        }
                    }
                    else if (wParam == WM_RBUTTONDOWN)
                    {
                        msg = "Right button down";
                        if (lParam.Location == pos_hidden)
                        {
                            boolMouseDownRight = true;
                        }
                    }
                    else if (wParam == WM_MBUTTONDOWN)
                    {
                        msg = "Middle button down";
                    }
                    Console.WriteLine(msg);
                    if (boolHidden)
                    {
                        boolUnhide = true;
                        boolHidden = false;
                        boolNext   = false;
                    }
                }
                else
                {
                    mouseMoved();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            if (boolNext)
            {
                return(CallNextHookEx(hhook, nCode, wParam, ref lParam));
            }
            else
            {
                Console.WriteLine("SKIPPING");
                //not sure... maybe this should return -1
                return(1);
            }
        }
예제 #3
0
        private int hookProc(int nCode, int wParam, ref Msllhookstruct lParam)
        {
            Boolean boolNext = true;

            try
            {
                if (wParam != WM_MOUSEMOVE)
                {
                    Console.WriteLine(wParam.ToString("X"));
                    String msg = "";
                    if (wParam == WM_MOUSEWHEEL)
                    {
                        short Delta = (short)(lParam.MouseData >> 16);

                        if (Delta > 0)
                        {
                            msg = "Scroll up";
                        }
                        else if (Delta < 0)
                        {
                            msg = "Scroll down";
                        }
                    }
                    else if (wParam == WM_LBUTTONUP)
                    {
                        msg = "Left button up";
                    }
                    else if (wParam == WM_RBUTTONUP)
                    {
                        msg = "Right button up";
                    }
                    else if (wParam == WM_MBUTTONUP)
                    {
                        msg = "Middle button up";
                    }
                    else if (wParam == WM_LBUTTONDOWN)
                    {
                        msg = "Left button down";
                    }
                    else if (wParam == WM_RBUTTONDOWN)
                    {
                        msg = "Right button down";
                        //test...
                        //Cursor.Position = new Point(1700, 700);
                    }
                    else if (wParam == WM_MBUTTONDOWN)
                    {
                        msg = "Middle button down";
                    }
                    //Label1.Text = msg;
                    //lastMessage = DateTime.Now;
                    Console.WriteLine(msg);
                }
                else
                {
                    //Label2.Text = lParam.Location.ToString();
                    Console.WriteLine("Mouse Move: {0}", lParam.Location.ToString());
                    startDrawing(lParam.Location);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            if (boolNext)
            {
                return(CallNextHookEx(hhook, nCode, wParam, ref lParam));
            }
            else
            {
                return(0);
            }
        }