//#include <iostream>
//#include <stdlib.h>
//#include <stdio.h>
//#include <thread>
//using namespace std;
//using namespace this_thread;
//void Key();
//void Key() {
// while (true) {
// system("input keyevent 'KEYCODE_K'");
// sleep_for(0.9s);
// }
//}
//int main()
//{
// thread th[10];
// for (int i = 0; i < 10; i++) {
// cout << "启动第" << i << "个线程\n";
// th[i] = thread(Key);
// th[i].detach();
// sleep_for(1s);
// }
// cout << "所有线程启动完成";
// while (true) {}
//}
//上面是安卓系统模拟按键K,下面是windows系统模拟按键K
//#include <iostream>
//#include <thread>
//#include <Windows.h>
//
//void simulateKeyPress(int keyCode) {
// INPUT input;
// input.type = INPUT_KEYBOARD;
// input.ki.wVk = keyCode;
// input.ki.dwFlags = 0;
// input.ki.time = 0;
// input.ki.dwExtraInfo = 0;
//
// SendInput(1, &input, sizeof(INPUT));
//}
//
//
//void Key();
//
//void Key() {
// while (true) {
// INPUT input;
// input.type = INPUT_KEYBOARD;
// input.ki.wVk = 'K';
// input.ki.dwFlags = 0;
// input.ki.time = 0;
// input.ki.dwExtraInfo = 0;
//
// SendInput(1, &input, sizeof(INPUT));
// std::this_thread::sleep_for(std::chrono::milliseconds(900));
// }
//}
//
//
//int main() {
// std::thread th[10];
//
// for (int i = 0; i < 10; i++) {
// std::cout << "启动第" << i << "个线程\n";
// th[i] = std::thread(Key);
// th[i].detach();//独立于主线程运行
// std::this_thread::sleep_for(std::chrono::seconds(1));
// }
//
// std::cout << "所有线程启动完成";
//
// while (true) {}
//
// return 0;
//}
//#include <iostream>
//#include <thread>
//#include <Windows.h>
#include <iostream>
#include <Windows.h>
void simulateKeyPress(int keyCode) {
//#include <iostream>
//#include <Windows.h>
INPUT input;
input.type = INPUT_KEYBOARD;
input.ki.wVk = keyCode;
input.ki.dwFlags = 0;
input.ki.time = 0;
input.ki.dwExtraInfo = 0;
SendInput(1, &input, sizeof(INPUT));
}
int main() {
// 模拟按下 'K' 键
for (size_t i = 0; i < 10; i++)
{
simulateKeyPress('E');
Sleep(1000);
}
return 0;
}```
windows原生的模拟按键
最新推荐文章于 2024-06-13 19:33:03 发布