1、keyboard event:
keybd_event(VK_CONTROL,0,0,0);
keybd_event(VK_MENU, 0, 0, 0);
keybd_event('S', 0, 0, 0);
keybd_event('S', 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);
::PostMessage(hWnd,WM_KEYDOWN,VK_CONTROL,0);
::PostMessage(hWnd,WM_KEYDOWN,VK_MENU,0);
::PostMessage(hWnd,WM_KEYDOWN,'1',0);
::PostMessage(hWnd,WM_KEYUP,'1',0);
::PostMessage(hWnd,WM_KEYUP,VK_MENU,0);
::PostMessage(hWnd,WM_KEYUP,VK_CONTROL,0);
2、mouse event:
CString gameCaption="XXXXX";
HWND hWnd=::FindWindow(NULL,gameCaption);
DWORD dwPid;
RECT rect;
POINT ptOld;
::GetWindowThreadProcessId(hWnd,&dwPid);
::GetWindowRect(hWnd,&rect);
::GetCursorPos(&ptOld);
::SetCursorPos(80,150);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
SetCursorPos(rect.left +200,rect.top +150);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
CString gameCaption="XXXXX";
HWND hWnd=::FindWindow(NULL,gameCaption);
::PostMessage(hWnd,WM_MOUSEMOVE, MK_LBUTTON, MAKELONG(80,130));
::PostMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(80,130));
::PostMessage(hWnd,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(80,130));
Sleep(10);
more Information,please click here.
http://blog.csdn.net/wangningyu/archive/2009/12/13/4994295.aspx
|