Windows10 VS2017 C++模擬點選按鍵

大囚長發表於2018-12-27

#include "pch.h"
#include <Windows.h>
#include <stdio.h>
#include <iostream>

using namespace std;


int main()
{
	Sleep(3000);

	system("start notepad");

	Sleep(3000);

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

	// 模擬按下'A'鍵
	for (int i = 0; i < 100; i++)
	{
		keybd_event('A', 0, 0, 0);
		keybd_event('A', 0, KEYEVENTF_KEYUP, 0);
	}
	

	// 模擬按下 CTRL + S
	keybd_event(VK_CONTROL, (BYTE)0, 0, 0);
	keybd_event('S', (BYTE)0, 0, 0);

	keybd_event('S', (BYTE)0, KEYEVENTF_KEYUP, 0);
	keybd_event(VK_CONTROL, (BYTE)0, KEYEVENTF_KEYUP, 0);

	cout << "Input over, press any key to exit." << endl;
	
	getchar();
	return 0;
}

參考文章:
https://blog.csdn.net/dxk539687357/article/details/69668936/

相關文章