Two days ago, I asked my classmates to help me become a king. He needed heroes, but I didn't have gold coins. I couldn't afford them. (How important is money!!) I have to brush gold coins in the clouds, but I'm so lazy that I don't want to brush them manually. So, try to do something about it. After a long battle (as if it wasn't too long), it was finally finished!
The code is written in C:
1 #include <stdio.h> 2 #include <windows.h> 3 #include <time.h> 4 #include <stdlib.h> 5 6 char *baseStr = "adb shell input tap "; 7 int info[8][3] = { 8 {0, 0, 0}, 9 {0, 0, 0}, 10 {0, 0, 0}, 11 {0, 0, 0}, 12 {0, 0, 0}, 13 {0, 0, 0}, 14 {0, 0, 0}, 15 {0, 0, 0}, 16 }; 17 18 /** 19 * Customize the multiplier function to find the b power of a 20 * @param int a 21 * @param int b 22 * @return int r 23 */ 24 int power(int a, int b) 25 { 26 int i, r = 1; 27 for (i = 0; i < b; i++) r *= a; 28 return r; 29 } 30 31 /** 32 * Custom Execution Function 33 * @param int dx x coordinate 34 * @param int dy y coordinate 35 */ 36 void func(int dx, int dy) 37 { 38 char dxStr[10]; // x Coordinate string 39 char dyStr[10]; // y Coordinate string 40 char str[100]; // adb Command string 41 42 strcpy(str, baseStr); 43 // Converting numbers to strings 44 itoa(dx, dxStr, 10); 45 itoa(dy, dyStr, 10); 46 // StringBuilder 47 strcat(str, dxStr); 48 strcat(str, " "); 49 strcat(str, dyStr); 50 system(str); // call system 51 system("cls"); // A warning will appear when using the simulator 52 } 53 54 /** 55 * Writing file 56 */ 57 void wFile(char *fileName) 58 { 59 int flag = 1, flag2 = 1; // sign 60 FILE *fp; 61 int startX, startY; // Reference coordinates 62 int dx, dy; // Relative coordinates 63 POINT pt = {0, 0}; 64 int startT = 0, t; // Start time and interval 65 int i = 0; 66 67 fp = fopen(fileName, "w"); 68 while (getch() == ' ') // Press the space bar to execute the loop 69 { 70 GetCursorPos(&pt); // Get the current position coordinates 71 if (flag) // Get reference coordinates 72 { 73 startX = (&pt)->x; 74 startY = (&pt)->y; 75 printf("The reference coordinates are: x=%d,y=%d", startX, startY); 76 flag = 0; 77 } 78 else 79 { 80 t = flag2 ? 0 : (clock() - startT); // Delay Time 81 if(flag2) flag2 = 0; 82 dx = (&pt)->x - startX; 83 dy = (&pt)->y - startY; 84 startT = clock(); // Get the current time as the next start time 85 // Assign values to arrays 86 if (t == 0) info[i][0] = t; 87 else info[i][0] = t - 500; 88 info[i][1] = dx; 89 info[i++][2] = dy; 90 fprintf(fp, "%d,%d,%d\n", (t - 500), dx, dy); // Store information in info.log In file 91 func(dx, dy); // Running Execution Function 92 } 93 } 94 fclose(fp); // Close file 95 } 96 97 int main() 98 { 99 FILE *out; // Files to read 100 char temp[10]; 101 char sc, nc, rc; 102 int i = 0, j, k; // Loop variable 103 char ch; // Storage value after file reading 104 int flag = 1; // sign 105 106 // change the window size 107 system("mode con cols=40 lines=20"); 108 109 system("adb devices"); 110 printf("If the equipment does not exist, it is not recommended to continue execution.\n Need to continue?y/n?"); 111 scanf(" %c", &sc); 112 if (sc != 'y' && sc != 'Y') exit(0); 113 114 // Determine whether a file exists 115 if ((out = fopen("info.log", "r")) == NULL) 116 { 117 printf("No record file was detected under the current folder. Do you need to create a new one? (File entry method, please refer to readme.txt)y/n?"); 118 scanf(" %c", &nc); 119 if (nc == 'y' || nc == 'Y') 120 { 121 wFile("info.log"); // write file info.log 122 flag = 0; // take flag Set 0 123 } 124 else exit(0); 125 } 126 127 // Determine whether you need to read from a file 128 if (flag) 129 { 130 i = 0; 131 j = 0; 132 printf("Record files have been found. Do you want to re-enter them? y/n?"); 133 scanf(" %c", &rc); 134 if (rc == 'y' || rc == 'Y') wFile("info.log"); // Rewrite file 135 // Read the contents of the file and give info Array assignment 136 while ((ch = fgetc(out)) != EOF) 137 { 138 // Judging whether it is? ',' Or line wrap 139 if (ch != ',' && ch != '\n') temp[i++] = ch; 140 else 141 { 142 i = 0; // i Set 0 143 info[j / 3][j % 3] = atoi(temp); // Assign values to arrays 144 for (k = 0; k < 10; k++) temp[k] = '\n'; // empty temp 145 j++; 146 } 147 } 148 } 149 fclose(out); // Close file 150 151 // Execution operation 152 while (1) 153 { 154 for (i = 0; i < 8; i++) 155 { 156 Sleep(info[i][0]); // delayed 157 func(info[i][1], info[i][2]); // implement 158 } 159 Sleep(3000); 160 } 161 return 0; 162 }
How to say, thank Professor Tan Haoqiang, Haha.
Links: https://pan.baidu.com/s/18rLpBahcP0nW7I5CSWRgtA
Extraction code: yslx
Some of them are not busy, haha, learning or playing, it will be meaningless (^_____________