windows鼠标消息处理与键盘模拟函数
1、鼠标坐标问题
BOOL GetWindowRect(
RECT x;//定义一个二维数组x
::GetWindowRect(hwnd,&x);
POINT P;//x,y RECT型 X 的指针
GetCursorPos(&p); //取当前鼠标坐标指针
SetCursorPos(x+r1.left,y+r1.top); //设置下一步鼠标坐标指针
SetCursorPos(p.x,p.y); //还原鼠标坐标
2、模拟鼠标消息
LRESULT SendMessage(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
int x=?,y=?;
//y<<16)+x=lParam
//lParam可由SPY++拦截获取,亦可计算
//eg.x=655;y=577 lparam 0x0241028f
// 0x 0172 01f3
// y=370 x= 499
左键单击模拟:
SendMessage(hwnd,WM_LBUTTONDOWN,0,(y<<16)+x);
SendMessage(hwnd,WM_LBUTTONUP,0,(y<<16)+x);
左键双击模拟:
SendMessage(hwnd,WM_LBUTTONDBLCLK,0,(y<<16)+x);
右键单击模拟:
SendMessage(hwnd,WM_RBUTTONDOWN,0,(y<<16)+x);
SendMessage(hwnd,WM_RBUTTONUP,0,(y<<16)+x);
右键双击模拟:
SendMessage(hwnd,WM_RBUTTONDBLCLK,0,(y<<16)+x);
2、鼠标事件
VOID mouse_event( DWORD dwFlags, DWORD dx, DWORD dy, DWORD dwData, DWORD dwExtraInfo );
左键单击消息:
mouse_event(mouse_event_LEFTUP,0,0,0,0); //第一个参数位 鼠标操作状态
mouse_event(mouse_event_LEFTDOWN,0,0,0,0);
左键双击消息:
mouse_event(mouse_event_LBUTTONDBLCLK,0,0,0,0);
右键单击消息
mouse_event(MOUSEEVENTF_REFTUP,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
右键双击消息:
mouse_event(mouse_event_RBUTTONDBLCLK,0,0,0,0);
键盘模拟函数
VOID keybd_event(
BYTE bVk,
BYTE bScan,
DWORD dwFlags,
PTR dwExtraInfo
);
调用:
keybd_event(13, 0, 0 ,0); //第一参数键值 13 回车