一、只是adb
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<thread>
#if defined(__linux__)
#include<unistd.h>
#elif defined(_WIN32)
#include<windows.h>
#endif
using namespace std;
#define THREAD_ADVERTISEMENT_SIZE 7
#define TAP_TIME 500
void my_p_sleep(int time) {
#if defined(__linux__)
sleep(time);
#elif defined(_WIN32)
Sleep((time*1000));
#endif
}
void my_m_sleep(int time) {
#if defined(__linux__)
usleep(time*1000);
#elif defined(_WIN32)
Sleep(time);
#endif
}
void tap_meal()
{
int i = TAP_TIME / 3;
while (i--)
{
int x[3] = { 410,662,904 };
int y[2] = { 712,1011 };
printf("meal[%d]:\n", i);
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
char command[40];
sprintf(command, "adb shell input tap %d %d", x[i], y[j]);
system(command);
printf("\n[%d]", i * 2 + j + 1);
}
}
my_p_sleep(10);
}
}
void tap_advertisement()
{
int i = TAP_TIME;
while (i--)
{
system("adb shell input tap 967 1740");
printf("Tap[%d] ", i);
}
}
int main()
{
thread threads_advertisement[THREAD_ADVERTISEMENT_SIZE];
thread thread_meal(tap_meal);
for (int i = 0; i < THREAD_ADVERTISEMENT_SIZE; i++)
{
threads_advertisement[i] = thread(tap_advertisement);
my_m_sleep(50);
}
for (int i = 0; i < THREAD_ADVERTISEMENT_SIZE; i++)
{
threads_advertisement[i].join();
}
thread_meal.join();
cout << "completion" << endl;
return 0;
}
二、OpenCV图像分析+adb
#include<iostream>
#include<unistd.h>
#include<thread>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
#define THREAD_ADVERTISEMENT_SIZE 10
#define TAP_TIME 1000
void tap_meal()
{
int i=TAP_TIME/3;
while(i--)
{
int x[3]={410,662,904};
int y[2]={712,1011};
printf("meal[%d]:\n",i);
for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
{
char command[40];
sprintf(command,"adb shell input tap %d %d",x[i],y[j]);
system(command);
printf("\n[%d]",i*2+j+1);
}
}
sleep(10);
}
}
void tap_advertisement()
{
int i=TAP_TIME;
while(i--)
{
system("adb shell input tap 967 1740");
printf("Tap[%d] ",i);
}
}
void tap_thanks()
{
int i=TAP_TIME;
int button_pos[2]={57,940};
int button_thanks[2]={400,1650};
while(i--)
{
system("adb shell screencap -p /sdcard/1.png");
system("adb pull /sdcard/1.png");
system("adb shell rm /sdcard/1.png");
Mat src=imread("./1.png",0);
src=src>200;
if((int)src.at<uchar>(button_pos[0],button_pos[1])==0)
{
char str[40];
sprintf(str,"adb shell input tap %d %d",button_thanks[0],button_thanks[1]);
system(str);
}
printf("\ntap_thanks\n");
sleep(4);
}
}
int main()
{
setvbuf(stdout,NULL,_IONBF,0);
thread threads_advertisement[THREAD_ADVERTISEMENT_SIZE];
thread thread_meal(tap_meal);
thread threads_thanks(tap_thanks);
for(int i=0;i<THREAD_ADVERTISEMENT_SIZE;i++)
{
threads_advertisement[i]=thread(tap_advertisement);
usleep(50000);
}
for(int i=0;i<THREAD_ADVERTISEMENT_SIZE;i++)
{
threads_advertisement[i].join();
}
thread_meal.join();
threads_thanks.join();
cout<<"completion"<<endl;
return 0;
}