#include <Windows.h> #include <stdlib.h> //打开程序或网页 void open(char *str) { ShellExecuteA(0, "open", str, 0, 0, 1); } //关闭程序 void close() { system("http://taskkill /f /im liebao.exe"); } //模拟键盘按下实现输入 void search() { keybd_event('G', 0, 0, 0);//g键按下 keybd_event('G', 0, 2, 0);//g键释放 keybd_event('G', 0, 0, 0); keybd_event('G', 0, 2, 0); keybd_event('1', 0, 0, 0); keybd_event('1', 0, 2, 0); keybd_event(0x0d, 0, 0, 0);//回车键按下 keybd_event(0x0d, 0, 2, 0);//回车键释放 } //鼠标移动到固定单元位置 void mouse_move(int x, int y) { //移动到绝对位置 行列的单元数为65535 求得每个像素多少个单元 与像素相乘就可以定位到具体位置 mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x * 65535 / 1920, y * 65535 / 1080, 0, 0); } //鼠标点击 void mouse_click() { mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); } void main() { while (1) { open("http://online.njtech.edu.cn"); Sleep(4000); mouse_move(1300, 230); mouse_click(); Sleep(300); search(); mouse_move(700, 400); Sleep(1000); mouse_click(); Sleep(2000); close(); } }