11平台dota改键精灵有问题

[转载]魔兽改键(仿11平台)
的参数格式一般都是整型的宏定义,调用时要进行转换,特别是整型的字节数,这部分基本到网上搜的代码段。
时总不能正常运行,最终页未能搞定,然后发现位的可以在位上运行(先前用写的简单的钩子位就不能运行在位上)。
,鼠标相对移动产生的诡异行为(竟然会自己改变移动的距离),键盘的按键编码,与的交互(现在还留着一个,长按键的效果很是不好,可惜好像搞不定)。
using&System.Collections.G
using&System.L
using&System.T
using&System.Windows.F
using&System.Runtime.InteropS
using&System.R
using&System.D
using&System.D
namespace&魔兽改键
&&static&class&Work
&&static&public&char[]&key&=&new&char[18];
&&static&public&int[]&x&=&new&int[18]&{&816,&872,&927,&983,&816,&872,&927,&983,&816,&872,&927,&983,&680,&731,&680,&731,&680,&731&};
&&static&public&int[]&y&=&new&int[18]&{&625,&625,&625,&625,&680,&680,&680,&680,&736,&736,&736,&736,&645,&645,&695,&695,&744,&744&};
&&static&int&enterN
&&static&int&
&&[DllImport("user32",&SetLastError&=&true)]
&&public&static&extern&IntPtr&GetForegroundWindow();
&&[DllImport("USER32.DLL",&CharSet&=&CharSet.Unicode)]
&&public&static&extern&IntPtr&FindWindow(string&lpClassName,
&&string&lpWindowName);
//&[DllImport("user32",&SetLastError&=&true)]
//&public&static&extern&int&GetWindowThreadProcessId(int&hwnd,&ref&int&lProcessId);
//&public&static&int&GetForegroundThread()
//&int&procid&=&0;
//&int&threadid&=&GetWindowThreadProcessId(GetForegroundWindow(),&ref&procid);
//&return&
&&[DllImport("user32",&CharSet&=&CharSet.Auto,&CallingConvention&=&CallingConvention.StdCall)]
&&public&static&extern&int&SetWindowsHookEx(HookType&idHook,&HOOKPROC&lpfn,&IntPtr&hInstance,&int&threadId);
&&[DllImport("user32",&CharSet&=&CharSet.Auto,&CallingConvention&=&CallingConvention.StdCall)]
&&public&static&extern&int&CallNextHookEx(int&hhk,&int&nCode,&int&wParam,&IntPtr&lParam);
&&[DllImport("user32",&CharSet&=&CharSet.Auto,&CallingConvention&=&CallingConvention.StdCall)]
&&public&static&extern&bool&UnhookWindowsHookEx(int&hhk);
&&public&enum&HookType
&&WH_KEYBOARD&=&2,//私有钩子
&&WH_KEYBOARD_LL&=&13//全局钩子
&&public&delegate&int&HOOKPROC(int&nCode,&int&wParam,&IntPtr&lParam);
&&static&int&hhk&=&0;
&&static&HOOKPROC&hookpro&=&new&HOOKPROC(MyKeyboardProc);
&&public&static&void&SetHook()
&&enterNum&=&0;
&&time&=&DateTime.Now.M
&&hhk&=&SetWindowsHookEx(HookType.WH_KEYBOARD_LL,hookpro&,&Process.GetCurrentProcess().Modules[0].BaseAddress,&0);
&&if&(hhk&==&0)&Console.WriteLine("改键预处理失败");
&&///&&summary&
&&///&声明键盘钩子的封送结构类型
&&///&&/summary&
&&[StructLayout(LayoutKind.Sequential)]
&&public&class&KeyboardHookStruct
&&public&int&vkC//表示一个1到254间的虚拟键盘码
&&public&int&scanC//表示硬件扫描码
&&public&int&
&&public&int&
&&public&int&dwExtraI
&&private&const&int&WM_KEYDOWN&=&0x100;//按下消息
&&private&const&int&VK_RETURN&=&13;//回车消息
&&private&const&int&VK_SPACE&=&13;//空格消息
&&public&static&int&MyKeyboardProc(int&nCode,&int&wParam,&IntPtr&lParam)
&&//在这里放置你的处理代码
&&int&ti&=&DateTime.Now.M
&&ti&=&(time&-&ti&+&1000)&%&1000;
&&if&(wParam&==&WM_KEYDOWN&&&&nCode&&=&0&&&&GetForegroundWindow()&==&FindWindow(null,&"Warcraft&III"))
&&if&(ti&&&100)&return&1;
&&time&=&DateTime.Now.M
&&KeyboardHookStruct&mykey&=&(KeyboardHookStruct)Marshal.PtrToStructure(lParam,&typeof(KeyboardHookStruct));
&&if&(mykey.vkCode&==&VK_RETURN)
&&enterNum++;
&&Console.WriteLine(enterNum);
&&return&CallNextHookEx(hhk,&nCode,&wParam,&lParam);
&&if&((enterNum&%&2)&==&1)&return&CallNextHookEx(hhk,&nCode,&wParam,&lParam);
&&for&(int&i&=&0;&i&&&key.L&i++)
&&if&(key[i]&==&'')&
&&if&(mykey.vkCode&==&(int)key[i])
&&Point&pp&=&Control.MouseP
&&Mouse.send(x[i],&y[i],pp.X,pp.Y);
&&return&1;
&&return&CallNextHookEx(hhk,&nCode,&wParam,&lParam);
&&public&static&bool&UnHook()
&&bool&f&=&UnhookWindowsHookEx(hhk);
&&hhk&=&0;
&&return&f;
&&static&class&Mouse{
&&[DllImport("user32.dll")]
&&public&static&extern&UInt32&SendInput(UInt32&nInputs,&Input[]&pInputs,&int&cbSize);
&&[StructLayout(LayoutKind.Explicit)]
&&public&struct&Input
&&[FieldOffset(0)]
&&public&Int32&
&&[FieldOffset(4)]
&&public&MouseInput&
&&[FieldOffset(4)]
&&public&tagKEYBDINPUT&
&&[FieldOffset(4)]
&&public&tagHARDWAREINPUT&
&&[StructLayout(LayoutKind.Sequential)]
&&public&struct&MouseInput
&&public&Int32&
&&public&Int32&
&&public&Int32&M
&&public&Int32&dwF
&&public&Int32&
&&public&IntPtr&dwExtraI
&&[StructLayout(LayoutKind.Sequential)]
&&public&struct&tagKEYBDINPUT
&&Int16&wVk;
&&Int16&wS
&&Int32&dwF
&&IntPtr&dwExtraI
&&[StructLayout(LayoutKind.Sequential)]
&&public&struct&tagHARDWAREINPUT
&&Int32&uM
&&Int16&wParamL;
&&Int16&wParamH;
&&const&int&MouseEvent_Absolute&=&0x8000;
&&const&int&MouserEvent_Hwheel&=&0x01000;
&&const&int&MouseEvent_Move&=&0x0001;
&&const&int&MouseEvent_Move_noCoalesce&=&0x2000;
&&const&int&MouseEvent_LeftDown&=&0x0002;
&&const&int&MouseEvent_LeftUp&=&0x0004;
&&const&int&MouseEvent_MiddleDown&=&0x0020;
&&const&int&MouseEvent_MiddleUp&=&0x0040;
&&const&int&MouseEvent_RightDown&=&0x0008;
&&const&int&MouseEvent_RightUp&=&0x0010;
&&const&int&MouseEvent_Wheel&=&0x0800;
&&const&int&MousseEvent_XUp&=&0x0100;
&&const&int&MousseEvent_XDown&=&0x0080;
&&public&static&void&send(int&i,int&j,int&x,int&y){
&&MouseInput&myMinput&=&new&MouseInput();
&&int&ScreenWidth&=&Screen.PrimaryScreen.WorkingArea.W
&&int&ScreenHeight&=&Screen.PrimaryScreen.WorkingArea.H
&&Console.WriteLine(ScreenWidth.ToString()&+&":"&+&ScreenHeight.ToString());
&&myMinput.Mousedata&=&0;
&&myMinput.time&=&0;
&&myMinput.dwExtraInfo&=&IntPtr.Z
&&Input[]&myInput&=&new&Input[1];
&&//先移动到目标位置单击一下
&&myMinput.dx&=&i&*&65335&/&1024;
&&myMinput.dy&=&j&*&65335&/&768;
&&myMinput.dwFlag&=&MouseEvent_Absolute&|&MouseEvent_Move&|&MouseEvent_LeftDown&|&MouseEvent_LeftUp;
&&myInput[0]&=&new&Input();
&&myInput[0].type&=&0;
&&myInput[0].mi&=&myM
&&UInt32&result&=&SendInput((uint)myInput.Length,&myInput,&Marshal.SizeOf(myInput[0].GetType()));
&&//回到原来所在的位置,需要等待一会,不然会作废前一次的单击
&&System.Threading.Thread.Sleep(30);
&&myMinput.dx&=&x&*&65335&/&ScreenW
&&myMinput.dy&=&y&*&65335&/&ScreenH
&&myMinput.dwFlag&=&MouseEvent_Absolute&|&MouseEvent_M
&&myInput[0]&=&new&Input();
&&myInput[0].type&=&0;
&&myInput[0].mi&=&myM
&&result&*=&SendInput((uint)myInput.Length,&myInput,&Marshal.SizeOf(myInput[0].GetType()));
//&if&(result&==&0)
//&MessageBox.Show("fail");
//&else&MessageBox.Show("succeed");
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

参考资料

 

随机推荐