自动打字机
Snow_WoIf
·
·
休闲·娱乐
不喜,勿喷!!!
#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;
}