⑴ 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);
}