跳到正文

休闲·娱乐

自动打字机

Snow_WoIf约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年9月5日
收录
2026年4月18日
更新
2026年11月11日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1

不喜,勿喷!!!

cmp
#include <Windows.h>
#include <string>
#include<bits/stdc++.h>

void SendString(const std::string& str) {
	INPUT ip;
	ip.type = INPUT_KEYBOARD;

	for (char c : str) {
		ip.ki.wVk = 0;
		ip.ki.wScan = c;
		ip.ki.dwFlags = KEYEVENTF_UNICODE;
		ip.ki.time = 0;
		ip.ki.dwExtraInfo = 0;

		// 发送按键按下事件
		SendInput(1, &ip, sizeof(INPUT));
		ip.ki.dwFlags = KEYEVENTF_KEYUP;
		SendInput(1, &ip, sizeof(INPUT));

		// 模拟输入间隔
		Sleep(1);
	}

	// 发送换行符
	ip.ki.wVk = VK_RETURN;
	ip.ki.wScan = 0;
	ip.ki.dwFlags = 0;
	SendInput(1, &ip, sizeof(INPUT));
	ip.ki.dwFlags = KEYEVENTF_KEYUP;
	SendInput(1, &ip, sizeof(INPUT));
}

int main() {
	std::string text;
	std::cout << "请输入要模拟输入的字符串: ";
	std::getline(std::cin, text);
	std::cout << "正在模拟输入,请将焦点切换到目标窗口..." << std::endl;
	Sleep(2000); // 允许用户切换到目标窗口
	SendString(text);
	return 0;
}
原文
存档评论4 条抓取于