hook 钩子程序三 mouse.cs (wow自动登录)

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Hook2
{
    public class Mouse
    {
        // Constructors
        public Mouse()
        {
        }


        // Methods
        [DllImport("user32.dll")]
        public extern static int SwapMouseButton(int bSwap);
        [DllImport("user32")]
        private extern static int ClipCursor(ref Mouse.RECT lpRect);
        [DllImport("user32.dll")]
        private extern static int GetCursorPos(ref Mouse.POINTAPI lpPoint);
        [DllImport("user32.dll")]
        public extern static bool ShowCursor(bool bShow);
        [DllImport("user32.dll")]
        public extern static int EnableWindow(int hwnd, int fEnable);
        [DllImport("user32.dll")]
        private extern static int GetWindowRect(int hwnd, ref Mouse.RECT lpRect);
        [DllImport("user32.dll")]
        public extern static int SetCursorPos(int x, int y);
        [DllImport("user32.dll")]
        public extern static int GetSystemMetrics(int nIndex);
        [DllImport("user32.dll")]
        public extern static int SetDoubleClickTime(int wCount);
        [DllImport("user32.dll")]
        public extern static int GetDoubleClickTime();
        [DllImport("kernel32.DLL")]
        public extern static void Sleep(int dwMilliseconds);
        [DllImport("user32.dll")]
        private extern static void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
        private static void Hide()
        {
            Mouse.ShowCursor(false);
        }

        private static void Show()
        {
            Mouse.ShowCursor(true);
        }

        public static void Center()
        {
            int x = Screen.PrimaryScreen.WorkingArea.Width / 2;
            int y = (Screen.PrimaryScreen.WorkingArea.Bottom / 2) + 0x32;
            Mouse.SetCursorPos(x, y);
        }

        public static void MoveAround(int iAround)
        {
            int num1 = 0x46;
            int x = Screen.PrimaryScreen.WorkingArea.Width / 2;
            int y = (Screen.PrimaryScreen.WorkingArea.Bottom / 2) + 0x32;
            if (iAround == 1)
            {
                y -= num1;
            }
            else if (iAround == 2)
            {
                x += num1;
            }
            else if (iAround == 3)
            {
                y += num1;
            }
            else if (iAround == 4)
            {
                x -= num1;
            }
            else
            {
                if (iAround == 5)
                {
                    x -= num1 * 5;
                }
            }
            Mouse.SetCursorPos(x, y);
        }

        public static void Move(int From_Handle_ToInt32, int To_Handle_ToInt32)
        {
            int x;
            Mouse.RECT rect1 = new Mouse.RECT();
            Mouse.RECT rect2 = new Mouse.RECT();
            Mouse.GetWindowRect(From_Handle_ToInt32, ref rect1);
            Mouse.GetWindowRect(To_Handle_ToInt32, ref rect2);
            if ((((rect1.left + rect1.right) / 2) - ((rect2.left + rect2.right) / 2)) > 0)
            {
                for (x = (rect1.left + rect1.right) / 2; x >= ((rect2.left + rect2.right) / 2); x--)
                {
                    Mouse.SetCursorPos(x, (rect1.top + rect1.bottom) / 2);
                    Mouse.Sleep(1);
                }
            }
            else
            {
                for (x = (rect1.left + rect1.right) / 2; x <= ((rect2.left + rect2.right) / 2); x++)
                {
                    Mouse.SetCursorPos(x, (rect1.top + rect1.bottom) / 2);
                    Mouse.Sleep(1);
                }
            }
            if ((((rect1.top + rect1.bottom) / 2) - ((rect2.top + rect2.bottom) / 2)) > 0)
            {
                for (x = (rect1.top + rect1.bottom) / 2; x >= ((rect2.top + rect2.bottom) / 2); x--)
                {
                    Mouse.SetCursorPos((rect2.left + rect2.right) / 2, x);
                    Mouse.Sleep(1);
                }
            }
            else
            {
                for (x = (rect1.top + rect1.bottom) / 2; x <= ((rect2.top + rect2.bottom) / 2); x++)
                {
                    Mouse.SetCursorPos((rect2.left + rect2.right) / 2, x);
                    Mouse.Sleep(1);
                }
            }
        }

        private static void DoubleClickTime_Set(int MouseDoubleClickTime)
        {
            Mouse.SetDoubleClickTime(MouseDoubleClickTime);
        }

        private static string DoubleClickTime_Get()
        {
            int num1 = Mouse.GetDoubleClickTime();
            return num1.ToString();
        }

        private static void DefaultRightButton()
        {
            Mouse.SwapMouseButton(1);
        }

        private static void DefaultLeftButton()
        {
            Mouse.SwapMouseButton(0);
        }

        public static void LeftDown()
        {
            Mouse.mouse_event(2, 0, 0, 0, 0);
        }

        public static void LeftUp()
        {
            Mouse.mouse_event(4, 0, 0, 0, 0);
        }

        public static void LeftClick()
        {
            Mouse.LeftDown();
            Mouse.LeftUp();
        }

        private static void MiddleDown()
        {
            Mouse.mouse_event(0x20, 0, 0, 0, 0);
        }

        private static void MiddleUp()
        {
            Mouse.mouse_event(0x40, 0, 0, 0, 0);
        }

        private static void MiddleClick()
        {
            Mouse.MiddleDown();
            Mouse.MiddleUp();
        }

        public static void RightDown()
        {
            Mouse.mouse_event(8, 0, 0, 0, 0);
        }

        public static void RightUp()
        {
            Mouse.mouse_event(0x10, 0, 0, 0, 0);
        }

        public static void RightClick()
        {
            Mouse.RightDown();
            Mouse.RightUp();
        }

        public static void Lock(Form ObjectForm)
        {
            Mouse.RECT rect1 = new Mouse.RECT();
            Mouse.GetWindowRect(ObjectForm.Handle.ToInt32(), ref rect1);
            Mouse.ClipCursor(ref rect1);
        }

        public static void SendMouse(Mouse.MouseFlag mouseKey)
        {
            Mouse.MouseFlag flag1 = mouseKey;
            if (flag1 <= Mouse.MouseFlag.RightDown)
            {
                switch (flag1)
                {
                    case Mouse.MouseFlag.LeftDown:
                        {
                            Mouse.LeftDown();
                            return;
                        }
                    case (Mouse.MouseFlag)3:
                        {
                            return;
                        }
                    case Mouse.MouseFlag.LeftUp:
                        {
                            Mouse.LeftUp();
                            return;
                        }
                    case Mouse.MouseFlag.RightDown:
                        {
                            goto Label_0045;
                        }
                    default:
                        {
                            return;
                        }
                }
            }
            if (flag1 == Mouse.MouseFlag.RightUp)
            {
                goto Label_004B;
            }
            switch (flag1)
            {
                case Mouse.MouseFlag.LeftClick:
                    {
                        Mouse.LeftClick();
                        return;
                    }
                case Mouse.MouseFlag.RightClick:
                    {
                        goto Label_0057;
                    }
                default:
                    {
                        return;
                    }
            }
        Label_0045:
            Mouse.RightDown();
            return;
        Label_004B:
            Mouse.RightUp();
            return;
        Label_0057:
            Mouse.RightClick();
        }

        public static void UnLock()
        {
            Mouse.RECT rect1 = new Mouse.RECT();
            rect1.top = 0;
            rect1.left = 0;
            rect1.bottom = Screen.PrimaryScreen.WorkingArea.Bottom;
            rect1.right = Screen.PrimaryScreen.WorkingArea.Right;
            Mouse.ClipCursor(ref rect1);
        }


        // Properties
        private static int FullScreenPosition_X
        {
            get
            {
                Mouse.POINTAPI pointapi1 = new Mouse.POINTAPI();
                Mouse.GetCursorPos(ref pointapi1);
                return pointapi1.x;
            }
        }

        private static int FullScreenPosition_Y
        {
            get
            {
                Mouse.POINTAPI pointapi1 = new Mouse.POINTAPI();
                Mouse.GetCursorPos(ref pointapi1);
                return pointapi1.y;
            }
        }

        private static string Type
        {
            get
            {
                if (Mouse.GetSystemMetrics(0x13) == 0)
                {
                    return "/u672c/u8ba1/u7b97/u673a/u5c1a/u672a/u5b89/u88c5/u9f20/u6807";
                }
                if (Mouse.GetSystemMetrics(0x4b) != 0)
                {
                    return Mouse.GetSystemMetrics(0x2b) + "/u952e/u6eda/u8f6e/u9f20/u6807";
                }
                return Mouse.GetSystemMetrics(0x2b) + "/u952e/u9f20/u6807";
            }
        }


        // Constants
        internal const byte SM_MOUSEPRESENT = 0x13;
        internal const byte SM_CMOUSEBUTTONS = 0x2b;
        internal const byte SM_MOUSEWHEELPRESENT = 0x4b;
        private const int MOUSEEVENTF_LEFTDOWN = 2;
        private const int MOUSEEVENTF_LEFTUP = 4;
        private const int MOUSEEVENTF_MIDDLEDOWN = 0x20;
        private const int MOUSEEVENTF_MIDDLEUP = 0x40;
        private const int MOUSEEVENTF_MOVE = 1;
        private const int MOUSEEVENTF_RIGHTDOWN = 8;
        private const int MOUSEEVENTF_RIGHTUP = 0x10;

        // Nested Types
        [StructLayout(LayoutKind.Sequential)]
        private struct POINTAPI
        {

            // Instance Fields
            public int x;
            public int y;
        }

        [StructLayout(LayoutKind.Sequential)]
        private struct RECT
        {

            // Instance Fields
            public int left;
            public int top;
            public int right;
            public int bottom;
        }

        public enum MouseFlag : uint
        {
            LeftDown = 2,
            LeftUp = 4,
            RightDown = 8,
            RightUp = 0x10,
            LeftClick = 0x81,
            RightClick = 0x82
        }
    }
}

你可能感兴趣的:(struct,properties,user,byte,hook,Constants)