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 ///
///
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); } } }}
手游推荐2024-01-15
手游推荐2024-01-15
手游推荐2024-01-15
手游推荐2024-01-15
手游推荐2024-01-15
手游推荐2024-01-15
手游推荐2024-01-15
手游推荐2024-01-15
手游推荐2024-01-15
手游攻略2020-11-17
LOL2019-04-02
LOL2019-04-02
LOL2018-02-10
LOL2016-05-13
LOL2016-05-02
LOL2016-04-07
LOL2016-03-20
LOL2016-02-21
LOL2016-01-28