模拟鼠标点击和键盘按下
1 //*--------------------------------------------------打开触摸板开始---------------------------------------------------*// 2 HWND hStatus=::FindWindow("Shell_TrayWnd",NULL); //得到任务栏窗口句柄 3 HWND hTray = ::FindWindowEx(hStatus,0,"TrayNotifyWnd",NULL); //获取托盘部分的窗口句柄 4 5 //获得触摸板所在的位置,由用户输入 6 UINT iPos; 7 BOOL flag; 8 iPos = GetDlgItemInt(IDC_EdtPos,&flag,TRUE); 9 if (iPos<1||iPos>10) 10 { 11 return; 12 } 13 //---------------保存当前鼠标的位置,用户对鼠标位置进行恢复 14 POINT p; 15 GetCursorPos(&p); 16 //---------------保存当前鼠标的位置,用户对鼠标位置进行恢复 17 CRect r; 18 ::GetWindowRect(hTray,&r); 19 SetCursorPos(r.left+10+24*(iPos-1),740); //设置鼠标位置到需要的位置 20 21 //模拟鼠标单击 22 mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); 23 mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); 24 //接下来靠键盘接收了。 25 Sleep(1000); 26 keybd_event(VK_CONTROL,0,0,0); 27 keybd_event('P',0,0,0); 28 keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0); 29 keybd_event('P',0,KEYEVENTF_KEYUP,0); 30 //*-------------------------------------------------------------打开触摸板结束------------------------------------------------*// 31 32 //---------------------------恢复鼠标的位置------------------ 33 Sleep(200); 34 SetCursorPos(p.x,p.y); 35 //---------------------------恢复鼠标的位置------------------ 36 37 //获取触摸板窗口的句柄 38 HWND hTouchPad =::FindWindow(NULL,"鼠标 属性"); 39 //获取触摸板窗口的位置 40 CRect rtTouchPad; 41 ::GetWindowRect(hTouchPad,&rtTouchPad); 42 SetCursorPos(rtTouchPad.left+300,rtTouchPad.top+40); 43 //------------------------------------------- 44 //模拟鼠标单击----“装置设定值” 45 mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); 46 mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); 47 48 //-------------------------------------- 49 SetCursorPos(rtTouchPad.left+200,rtTouchPad.top+200); 50 //模拟鼠标单击---“启用” 51 mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); 52 mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); 53 54 //模拟回车键按下 55 Sleep(200); 56 keybd_event(VK_RETURN, 0, 0, 0);
感觉还是很复杂,不知道还有没有更简单的方法。
https://files.cnblogs.com/tk091/traypad.rar