本文共 1368 字,大约阅读时间需要 4 分钟。
通过keybd_event和mouse_event功能函数,操作鼠标键盘。
#include#include #include void open(const char *str){ ShellExecuteA(0, "open", str, 0, 0, 0);}void close(){ system("taskkill /f /im baidubrowser.exe");}void input()//模拟键盘输入{ keybd_event('Z', 0, 0, 0);//按下 keybd_event('Z', 0, 2, 0);//抬起 Sleep(300); keybd_event('H', 0, 0, 0);//按下 keybd_event('H', 0, 2, 0);//抬起 Sleep(300); keybd_event('E', 0, 0, 0);//按下 keybd_event('E', 0, 2, 0);//抬起 Sleep(300); keybd_event('N', 0, 0, 0);//按下 keybd_event('N', 0, 2, 0);//抬起 Sleep(300); keybd_event('G', 0, 0, 0);//按下 keybd_event('G', 0, 2, 0);//抬起 Sleep(300); keybd_event('R', 0, 0, 0);//按下 keybd_event('R', 0, 2, 0);//抬起 Sleep(300); keybd_event('O', 0, 0, 0);//按下 keybd_event('O', 0, 2, 0);//抬起 Sleep(300); keybd_event('N', 0, 0, 0);//按下 keybd_event('N', 0, 2, 0);//抬起 Sleep(300); keybd_event('G', 0, 0, 0);//按下 keybd_event('G', 0, 2, 0);//抬起 Sleep(300); keybd_event(0x0D, 0, 0, 0);//按下 keybd_event(0x0D, 0, 2, 0);//抬起}void click(){ //SetCursorPos(200, 800); //移动到屏幕位置 mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, 700 * 65535 / 1920, 420 * 65535 / 1080, 0, 0); Sleep(500); mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);}void main(){ open("http://blog.csdn.net/waldmer"); Sleep(5000); //input(); //Sleep(5000); click(); Sleep(5000); close(); system("pause");}