League of legends auxiliary lol hook method not to be kicked of lol hook script


Call API to set the mouse position and simulate the right mouse button to make people walk around, global hooks, etc

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
namespace LOLSetCursor
{
    public class Hook
    {
        static bool IsStartThread = false;
        [StructLayout(LayoutKind.Sequential)]
        public class KeyBoardHookStruct
        {
            public int vkCode;
            public int scanCode;
            public int flags;
            public int time;
            public int dwExtraInfo;
        }
        public class SetPaint
        {
            public int X;
            public int Y;
            public int rows;
        }
        [Flags]  
        enum MouseEventFlag : uint 
        {  
            Move = 0x0001,  
            LeftDown = 0x0002,  
            LeftUp = 0x0004,  
            RightDown = 0x0008,  
            RightUp = 0x0010,  
            MiddleDown = 0x0020,  
            MiddleUp = 0x0040,  
            XDown = 0x0080,  
            XUp = 0x0100,  
            Wheel = 0x0800,  
            VirtualDesk = 0x4000,  
            Absolute = 0x8000  
        }
        // entrust
        public delegate int HookProc(int nCode, int wParam, IntPtr lParam);
        static int hHook = 0;
        public const int WH_KEYBOARD_LL = 13;
        // Release the key constant
        private const int KEYEVENTF_KEYUP = 2;
        //LowLevel Keyboard intercept, if yes WH_KEYBOARD = 2 Can not intercept the system keyboard, Acrobat Reader It will get the keyboard before you intercept it.
        static HookProc KeyBoardHookProcedure;
        #region  call API
        // Set the hook
        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
        // Draw hooks
        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern bool UnhookWindowsHookEx(int idHook);
        // Under the call 1 A hook
        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern int CallNextHookEx(int idHook, int nCode, int wParam, IntPtr lParam);
        // Gets the module handle
        [DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr GetModuleHandle(string name);
        // Find the target process window
        [DllImport("user32.dll")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        // Find child form
        [DllImport("user32.dll", EntryPoint = "FindWindowEX")]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent,
            IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        // Set the process window to the top
        [DllImport("USER32.DLL")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);
        // Simulated keyboard event
        [DllImport("User32.dll")]
        public static extern void keybd_event(Byte bVk, Byte bScan, Int32 dwFlags, Int32 dwExtraInfo);
        // Set mouse position
        [DllImport("user32.dll")]
        static extern bool SetCursorPos(int X, int Y);
        // Simulated mouse button
        [DllImport("user32.dll")]
        static extern void mouse_event(MouseEventFlag flsgs, int dx, int dy, uint data, UIntPtr extraInfo);
        #endregion
        /// <summary>
        ///  Install hooks
        /// </summary>
        public void Hook_Start()
        {
            // Install hooks
            if (hHook == 0)
            {
                KeyBoardHookProcedure = new HookProc(KeyBoatdHookProc);
                hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyBoardHookProcedure,
                        IntPtr.Zero, 0);
                if (hHook == 0) Hook_Clear(); //hook Setup failed
            }
        }
        /// <summary>
        ///  uninstall Hook
        /// </summary>
        public static void Hook_Clear()
        {
            bool retKeyboard = true;
            if (hHook != 0)
            {
                retKeyboard = UnhookWindowsHookEx(hHook);
                hHook = 0;
            }
        }
        public static int KeyBoatdHookProc(int nCode, int wParam, IntPtr lParam)
        {
            Thread thread1 = new Thread(StartCursor);
            SetPaint sp = new SetPaint();
            sp.X = Screen.PrimaryScreen.Bounds.Width;
            sp.Y = Screen.PrimaryScreen.Bounds.Height;
            sp.rows = 0;
            // Monitor user keyboard input
            KeyBoardHookStruct input = (KeyBoardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyBoardHookStruct));
            Keys k = (Keys)Enum.Parse(typeof(Keys), input.vkCode.ToString());
            if (input.vkCode == (int)Keys.Control || input.vkCode == (int)Keys.Shift || input.vkCode == (int)Keys.F1)
            {
                thread1.IsBackground = true;
                IsStartThread = true;
                thread1.Start(sp);
            }
            else if (input.vkCode == (int)Keys.Control || input.vkCode == (int)Keys.Shift || input.vkCode == (int)Keys.F2)
            {
                Hook_Clear();
                if (null != thread1)
                {
                    thread1.Abort();
                    IsStartThread = false;
                }
            }
            return CallNextHookEx(hHook, nCode, wParam, lParam);
        }

        static void StartCursor(object list)
        {
            SetPaint spaint = list as SetPaint;
            int sWhith = spaint.X;
            int sHeight = spaint.Y;
            int dx = 0;
            int dy = 0;

            while (IsStartThread)
            {               
                if (3 < spaint.rows) spaint.rows = 0;
                switch (spaint.rows)
                {
                    case 0:
                        dx = sWhith  / 3;
                        dy = sHeight / 3;
                        break;
                    case 1:
                        dy = dy * 2;
                        break;
                    case 2:
                        dx = dx * 2;
                        break;
                    case 3:
                        dy = dy / 2;
                        break;
                    default:
                        break;
                }
                spaint.rows++;
                //MessageBox.Show("width:"+sWhith+" height:"+sHeight+ " X:" + dx + " Y:" + dy+" rows:"+spaint.rows);
                SetCursorPos(dx, dy);
                mouse_event(MouseEventFlag.RightDown | MouseEventFlag.RightUp, 0, 0, 0, UIntPtr.Zero);
                Thread.Sleep(10000);
            }
        }
    }
}