当前位置: 移动技术网 > IT编程>开发语言>c# > 英雄联盟辅助lol挂机不被踢的方法(lol挂机脚本)

英雄联盟辅助lol挂机不被踢的方法(lol挂机脚本)

2019年07月18日  | 移动技术网IT编程  | 我要评论
调用api设置鼠标位置并模拟鼠标右键让人物走动,全局钩子等 复制代码 代码如下:using system;using system.collections

调用api设置鼠标位置并模拟鼠标右键让人物走动,全局钩子等

复制代码 代码如下:

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  
        }

        //委托
        public delegate int hookproc(int ncode, int wparam, intptr lparam);
        static int hhook = 0;
        public const int wh_keyboard_ll = 13;
        //释放按键的常量
        private const int keyeventf_keyup = 2;
        //lowlevel键盘截获,如果是wh_keyboard=2,并不能对系统键盘截取,acrobat reader会在你截取之前获得键盘。
        static hookproc keyboardhookprocedure;

        #region 调用api
        //设置钩子
        [dllimport("user32.dll", charset = charset.auto, callingconvention = callingconvention.stdcall)]
        public static extern int setwindowshookex(int idhook, hookproc lpfn, intptr hinstance, int threadid);

        //抽调钩子
        [dllimport("user32.dll", charset = charset.auto, callingconvention = callingconvention.stdcall)]
        public static extern bool unhookwindowshookex(int idhook);

        //调用下一个钩子
        [dllimport("user32.dll", charset = charset.auto, callingconvention = callingconvention.stdcall)]
        public static extern int callnexthookex(int idhook, int ncode, int wparam, intptr lparam);

        //获得模块句柄
        [dllimport("kernel32.dll", charset = charset.auto, callingconvention = callingconvention.stdcall)]
        public static extern intptr getmodulehandle(string name);

        //寻找目标进程窗口
        [dllimport("user32.dll")]
        public static extern intptr findwindow(string lpclassname, string lpwindowname);

        //查找子窗体
        [dllimport("user32.dll", entrypoint = "findwindowex")]
        public static extern intptr findwindowex(intptr hwndparent,
            intptr hwndchildafter, string lpszclass, string lpszwindow);


        //设置进程窗口到最前
        [dllimport("user32.dll")]
        public static extern bool setforegroundwindow(intptr hwnd);

        //模拟键盘事件
        [dllimport("user32.dll")]
        public static extern void keybd_event(byte bvk, byte bscan, int32 dwflags, int32 dwextrainfo);

        //设置鼠标位置
        [dllimport("user32.dll")]
        static extern bool setcursorpos(int x, int y);

        //模拟鼠标按键
        [dllimport("user32.dll")]
        static extern void mouse_event(mouseeventflag flsgs, int dx, int dy, uint data, uintptr extrainfo);
        #endregion
        /// <summary>
        /// 安装钩子
        /// </summary>
        public void hook_start()
        {
            //安装钩子
            if (hhook == 0)
            {
                keyboardhookprocedure = new hookproc(keyboatdhookproc);
                hhook = setwindowshookex(wh_keyboard_ll, keyboardhookprocedure,
                        intptr.zero, 0);
                if (hhook == 0) hook_clear(); //hook设置失败
            }
        }

        /// <summary>
        /// 卸载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;
            //监控用户键盘输入
            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);
            }
        }
    }
}

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网