鼠标键盘模拟

发送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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值