⑴ c语言 怎样模拟鼠标键盘操作
函数原型:
VOID keybd_event( BYTE bVk, BYTE bScan, DWORD dwFlags, DWORD dwExtraInfo );
4个参数都是输入参数。
bVk:键名,例如: VK_NUMPAD7,VK_BACK, VK_TAB,VK_SHIFT,VK_F1,。。。
keybd_event(VK_MENU,0xb8,0 , 0); -- 按下Alt 键
keybd_event(VK_MENU,0xb8,KEYEVENTF_KEYUP,0); -- 放开 Alt 键 (复位,弹上来)
===
下面程序模拟按 notepad 编辑器。等于C语言 system("notepad"); 弹出 记事本。
void simu_notepad()
{
keybd_event(VkKeyScan('N'),1,0,0);
keybd_event(VkKeyScan('N'),1,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('O'),0x98,0,0); keybd_event(VkKeyScan('O'),0x98,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('T'),0x94,0,0); keybd_event(VkKeyScan('T'),0x94,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('E'),0x92,0,0); keybd_event(VkKeyScan('E'),0x92,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('P'),0x99,0,0); keybd_event(VkKeyScan('P'),0x99,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('A'),0x9E,0,0); keybd_event(VkKeyScan('A'),0x9E,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('D'),0xA0,0,0); keybd_event(VkKeyScan('D'),0xA0,KEYEVENTF_KEYUP,0);
keybd_event(VK_RETURN,1,0,0);
keybd_event(VK_RETURN,1,KEYEVENTF_KEYUP,0);
}