日期:2014-05-18 浏览次数:21319 次
KeyboardHook keyboardHook = new KeyboardHook();//全局按键 //查找窗口 [DllImport("user32.dll")] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); //可将最小化窗口还原 [DllImport("user32.dll")] private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); //将指定窗口激活 [DllImport("user32.dll ")] private static extern bool SetForegroundWindow(IntPtr hWnd); //设置鼠标位置 [DllImport("user32.dll")] private static extern bool SetCursorPos(int X, int Y); //设置窗口位置和大小 [DllImport("user32.dll")] private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndlnsertAfter, int X, int Y, int cx, int cy, uint Flags); //模拟鼠标 [DllImport("user32.dll")] private static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo); private const int SW_RESTORE = 9; //将窗口还原的参数 private const uint SWP_SHOWWINDOW = 0x0040; //设置窗口位置的参数 private const int MOUSEEVENTF_LEFTDOWN = 0x0002; //模拟鼠标左键按下 private const int MOUSEEVENTF_LEFTUP = 0x0004; //模拟鼠标左键抬起 void keyboardHook_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F2) { if (lvInfo.SelectedItems.Count > 0) { IntPtr findPtr = FindWindow(null, "World of Warcraft");//World of Warcraft为游戏在任务栏的名称 ShowWindow(findPtr, SW_RESTORE); //将窗口还原 SetForegroundWindow(findPtr);//将指定窗口激活 if (findPtr.ToInt32()!=0) { SymmetricMethod sm = new SymmetricMethod(); //设置窗口位置和大小 SetWindowPos(findPtr, (IntPtr)(-1), 0, 0, 700, 550, SWP_SHOWWINDOW); System.Threading.Thread.Sleep(500); SetCursorPos(300, 300); //设置鼠标位置 mouse_event(0x0002, 0, 0, 0, 0); //模拟鼠标按下操作 mouse_event(0x0004, 0, 0, 0, 0); //模拟鼠标放开操作 System.Threading.Thread.Sleep(1000); SendKeys.Send(lvInfo.SelectedItems[0].SubItems[1].Text); //模拟键盘输入游戏ID SendKeys.Send("{TAB}"); //模拟键盘输入TAB SendKeys.Send(sm.Decrypto(lvInfo.SelectedItems[0].SubItems[2].Text)); //模拟键盘输入游戏密码 SendKeys.Send("{ENTER}"); //模拟键盘输入ENTER } else {