1. 程式人生 > >c++模擬按鍵

c++模擬按鍵

#include <Windows.h>

int main()
{
    Sleep(3000);

    // 模擬點選右鍵
    mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);

    // 模擬按下'A'鍵
    keybd_event('A', 0, 0, 0);
    keybd_event('A', 0, KEYEVENTF_KEYUP, 0);

    // 模擬按下 CTRL + F
    keybd_event(VK_CONTROL, (BYTE)
0, 0, 0); keybd_event('F', (BYTE)0, 0, 0); keybd_event('F', (BYTE)0, KEYEVENTF_KEYUP, 0); keybd_event(VK_CONTROL, (BYTE)0, KEYEVENTF_KEYUP, 0); getchar(); return 0; }