VS2017运行通过,其他编译器不详
版权由本人编写,禁止魔改用于商业用途
#include <stdio.h>
#include <windows.h> //windows系统的一些资源
//单键
void PressKey(BYTE vkey)
{
keybd_event(vkey, 0, 0, 0);
Sleep(50);
keybd_event(vkey, 0, 2, 0);
Sleep(50);
}
//双键
void PressKey(BYTE vkey1, BYTE vkey2)
{
keybd_event(vkey1, 0, 0, 0);
Sleep(50);
keybd_event(vkey2, 0, 0, 0);
Sleep(50);
keybd_event(vkey2, 0, 2, 0);
Sleep(50);
keybd_event(vkey1, 0, 2, 0);
Sleep(50);
}
int main(){
//获取到QQ的主界面 UNICODE 多字节字符集(c语言的风格)
HWND qqhwnd = FindWindow(L"TXGuiFoundation", L"QQ");
while (1){
SetForegroundWindow(qqhwnd);
PressKey(VK_TAB);
PressKey(VK_TAB);
while (1){
PressKey(VK_DOWN);
PressKey(VK_RETURN);
if (qqhwnd != GetForegroundWindow())
return;
}
PressKey(VK_CONTROL, 'V');
PressKey(VK_RETURN);//发送
PressKey(VK_ESCAPE);//关闭对话框
}
return 0;
}
定义一个窗口的句柄
//HWND hwnd = FindWindow(NULL, L"Hacker-Li");
//for (int i = 0; i < 100; i++)
//{
// SendMessage(hwnd,WM_PASTE,0,0); //往一个窗口种发送指令
// SendMessage(hwnd, WM_KEYDOWN, VK_RETURN, 0);
//}