发送a字符到当前活动窗口,大小写和当前capslock有关 keybd_event(VK_CAPITAL, 0, 0 ,0); keybd_event(VK_CAPITAL, 0, KEYEVENTF_KEYUP ,0); keybd_event('A', 0, 0 ,0); keybd_event('A', 0, KEYEVENTF_KEYUP ,0); 具体的虚拟键的值见附表 mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); POINT point; GetCursorPos(&point); SetCursorPos(500,500); Window2000/NT/XP已经不提倡用这个函数了,上面的方法只是为了让大家开阔一下思路,怎么替代呢,呵呵,看下面,所以上面的所有代码都可以用这个来完成 //2000下用这个代替 ,包含 "winable.h" 输入的Win+R的代码 INPUT input[4]; memset(input, 0, sizeof(input)); input[0].type = input[1].type = input[2].type = input[3].type = INPUT_KEYBOARD; input[0].ki.wVk = input[3].ki.wVk = VK_LWIN; input[1].ki.wVk = input[2].ki.wVk = 'R'; //接下来释放它,这一点很重要。 input[2].ki.dwFlags = input[3].ki.dwFlags = KEYEVENTF_KEYUP; input[0].ki.time = input[1].ki.time = input[2].ki.time = input[3].ki.time = GetTickCount(); SendInput(4, input, sizeof(INPUT)); 键盘输入模拟代码 SetCursorPos(500,500); INPUT input[2]; memset(input, 0, sizeof(input)); input[0].type = input[1].type = INPUT_MOUSE; input[0].mi.dwFlags = MOUSEEVENTF_RIGHTDOWN; input[1].mi.dwFlags = MOUSEEVENTF_RIGHTUP; input[0].ki.time = input[1].ki.time = GetTickCount(); SendInput(2, input, sizeof(INPUT)); The SendInput function synthesizes keystrokes, mouse motions, and button clicks. Syntax UINT SendInput( UINT nInputs, LPINPUT pInputs, int cbSize ); Parameters nInputs [in] Number of structures in the pInputs array. pInputs [in] Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream. cbSize [in] Specifies the size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function fails. Return Value The function returns the number of events that it successfully inserted into the keyboard or mouse input stream. If the function returns zero, the input was already blocked by another thread. To get extended error information, call GetLastError. Microsoft Windows Vista. This function fails when it is blocked by User Interface Privilege Isolation (UIPI). Note that neither GetLastError nor the return value will indicate the failure was caused by UIPI blocking. The INPUT structure is used by SendInput to store information for synthesizing input events such as keystrokes, mouse movement, and mouse clicks. Syntax typedef struct tagINPUT { DWORD type; union {MOUSEINPUT mi; KEYBDINPUT ki; HARDWAREINPUT hi; }; }INPUT, *PINPUT; Members type Specifies the type of the input event. This member can be one of the following values. INPUT_MOUSE The event is a mouse event. Use the mi structure of the union. INPUT_KEYBOARD The event is a keyboard event. Use the ki structure of the union. INPUT_HARDWARE Windows 95/98/Me: The event is from input hardware other than a keyboard or mouse. Use the hi structure of the union. mi A MOUSEINPUT structure that contains information about a simulated mouse event. ki A KEYBDINPUT structure that contains information about a simulated keyboard e
鼠标键盘模拟
最新推荐文章于 2024-09-11 12:43:25 发布
这篇博客介绍了如何在Windows环境下使用API函数keybd_event和mouse_event进行键盘和鼠标的模拟操作,包括发送按键、点击鼠标等。还提到了SendInput函数作为替代方法,并详细解释了这些函数的参数和使用场景。对于键盘模拟,讨论了大小写敏感性和CapsLock状态的影响。同时,文章提及了Windows NT/2000/XP之后版本推荐使用SendInput函数代替keybd_event和mouse_event。
摘要由CSDN通过智能技术生成