首页 > 其他分享 > coc仓库--minitouch控制函数封装

coc仓库--minitouch控制函数封装

时间:2023-07-18 23:14:12浏览次数:48  
标签:std string -- fwrite minitouch x2 int coc wirteFile

minitouch控制函数封装

minitouch的github地址:

1.原函数

void click(FILE *wirteFile, const std::string *ADB_IP, int x, int y)
{
    std::string s = "d 0 " + std::to_string(x) + " " + std::to_string(y) + " " + "50\n";
    fwrite(s.data(), 1, s.length(), wirteFile);
    fwrite("c\n", 1, sizeof("c"), wirteFile);
    fflush(wirteFile);
    sleepMills(30);
    fwrite("u 0\n", 1, sizeof("u 0"), wirteFile);
    fwrite("c\n", 1, sizeof("c"), wirteFile);
    fflush(wirteFile);
}

void swipe(FILE *wirteFile, const std::string *ADB_IP, int x1, int y1, int x2, int y2, const int time)
{
    std::string s = "d 0 " + std::to_string(x1) + " " + std::to_string(y1) + " " + "50\n";
    fwrite(s.data(), 1, s.length(), wirteFile);
    fwrite("c\n", 1, sizeof("c"), wirteFile);
    fflush(wirteFile);
    sleepMills(time);
    float r = (float)(y2 - y1) / (x2 - x1);
    std::cout << "r = " << r << std::endl;
    short space = 20;
    if (x1 < x2)
    {
        std::cout << "r为正向步进:" << r << "  and  x1 < x2" << std::endl;
        for (size_t i = 0; i * space + x1 < x2; i++)
        {
            s = "m 0 " + std::to_string(i * space + x1) + " " + std::to_string((short)(y1 + (short)i * space * r)) + " " + "50\n";
            // std::cout << s.data()<< std::endl;
            fwrite(s.data(), 1, s.length(), wirteFile);
            fwrite("c\n", 1, sizeof("c"), wirteFile);
            fflush(wirteFile);
            sleepMills(30);
        }
    }
    else if (x1 >= x2)
    {
        std::cout << "r为正向步进:" << r << "  and  *x1 >= *x2" << std::endl;
        for (size_t i = 0; x1 - i * space > x2; i++)
        {
            s = "m 0 " + std::to_string(x1 - i * space) + " " + std::to_string((short)(y1 - (short)i * space * r)) + " " + "50\n";
            fwrite(s.data(), 1, s.length(), wirteFile);
            fwrite("c\n", 1, sizeof("c"), wirteFile);
            fflush(wirteFile);
            sleepMills(30);
        }
    }

    fwrite("u 0\n", 1, sizeof("u 0"), wirteFile);
    fwrite("c\n", 1, sizeof("c"), wirteFile);
    fflush(wirteFile);
    // std::string cmd = "adb -s " + *ADB_IP + " shell input swipe " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + time;
    // runShellNoReturn(cmd.data());
}
void doubleSwipe(FILE *wirteFile, const std::string *ADB_IP, int x1, int y1, int x2, int y2, const int time)
{
    std::string s0 = "d 0 " + std::to_string(x1) + " " + std::to_string(y1) + " " + "50\n";
    std::string s1 = "d 1 " + std::to_string(x2) + " " + std::to_string(y2) + " " + "50\n";
    fwrite(s0.data(), 1, s0.length(), wirteFile);
    fwrite(s1.data(), 1, s1.length(), wirteFile);
    fwrite("c\n", 1, sizeof("c"), wirteFile);
    fflush(wirteFile);
    sleepMills(1000);
    float r = (float)(y2 - y1) / (x2 - x1);
    std::cout << "r = " << r << std::endl;
    short space = 20;
    if (x1 < x2)
    {
        std::cout << "r为正向步进:" << r << "  and  x1 < x2" << std::endl;
        for (size_t i = 0; i * space + x1 < (x1 + x2) / 2; i++)
        {
            s0 = "m 0 " + std::to_string(i * space + x1) + " " + std::to_string((short)(y1 + (short)i * space * r)) + " " + "50\n";
            s1 = "m 1 " + std::to_string(x2 - i * space) + " " + std::to_string((short)(y2 - (short)i * space * r)) + " " + "50\n";
            // std::cout << s.data()<< std::endl;
            fwrite(s0.data(), 1, s0.length(), wirteFile);
            fwrite(s1.data(), 1, s1.length(), wirteFile);
            fwrite("c\n", 1, sizeof("c"), wirteFile);
            fflush(wirteFile);
            sleepMills(90);
        }
    }
    else if (x1 >= x2)
    {
        std::cout << "r为正向步进:" << r << "  and  *x1 >= *x2" << std::endl;
        for (size_t i = 0; x1 - i * space > (x1 + x2) / 2; i++)
        {
            s0 = "m 0 " + std::to_string(x1 - i * space) + " " + std::to_string((short)(y1 - (short)i * space * r)) + " " + "50\n";
            s1 = "m 1 " + std::to_string(i * space + x2) + " " + std::to_string((short)(y2 + (short)i * space * r)) + " " + "50\n";
            fwrite(s0.data(), 1, s0.length(), wirteFile);
            fwrite(s1.data(), 1, s1.length(), wirteFile);
            fwrite("c\n", 1, sizeof("c"), wirteFile);
            fflush(wirteFile);
            sleepMills(90);
        }
    }

    fwrite("u 0\n", 1, sizeof("u 0"), wirteFile);
    fwrite("u 1\n", 1, sizeof("u 1"), wirteFile);
    fwrite("c\n", 1, sizeof("c"), wirteFile);
    fflush(wirteFile);
    // std::string cmd = "adb -s " + *ADB_IP + " shell input swipe " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + time;
    // runShellNoReturn(cmd.data());
}
void maginfy(FILE *wirteFile, const std::string *ADB_IP)
{
    int homeAttackMapX = 977;
    int homeAttackMapY = 1769; // 家乡搜索坐标
    int homeLookforX = 666;
    int homeLookforY = 394; // 搜索地图
    doubleSwipe(wirteFile, ADB_IP, homeAttackMapX - 300, homeAttackMapY, homeLookforX - 300, homeLookforY);
}

2.函数解析

*其实整体思路很简单,就是去调用minitouch的api来控制手机
*首先要通过添加popen()来创建一个输入流,也就是mode要设置成“w”,然后接收这个io流指针。
*对这个io流写入命令:
*fwrite()写入时要注意,命令的最后最好带上"\n"。
*每次fwirte("c\n)后,都要通过fflush刷新缓存区。
*每次刷新后,都要适当设置延迟。
*其实触控的运动轨迹是可以设置的很“真人”的,不过算法这块得花上不少功夫。

标签:std,string,--,fwrite,minitouch,x2,int,coc,wirteFile
From: https://www.cnblogs.com/yuxiannana/p/17564362.html

相关文章

  • 你的嘴就是你的风水
    你的嘴,就是你的风水 2023-04-1206:37一个人说什么话,他就是什么人!这句话,一点都不假!喜欢说刻薄话的人,一般心胸狭窄;喜欢说鼓励话的人,一般为人乐观。一个人的嘴巴,彰显的是一个人的内心,暴露的是一个人的修养,表明的是一个人的情绪。会说话的人,通过与人交流,给人安抚,......
  • 【Azure Redis】Redis导入备份文件(RDB)失败的原因
    问题描述在测试AzureRedis的导入/导出备份文件的功能中,突然发现在Redis4.0上导入的时候,一直报错。 问题解答因为门户上只是显示导入失败,没有任何错误消息说明。根据常理推断,Redis的RDB文件格式都具有一致性。居然会出现导入失败,所以非常不合常理。但为什么会出现这样的情......
  • 练习10.6
    用std::fill_n把一个int序列填充为0#include<iostream>#include<vector>#include<algorithm>#include<numeric>usingnamespacestd;intmain(intargc,char*argv[]){vector<int>v{1,2,3,4,5};std::fill_n(v.begin(),v.......
  • Mysql基础6-常用数据库函数
    一、字符串函数1、常见Mysql内置字符串函数concat(s1,s2,s3,...):字符串拼接,将s1,s2,s3...等拼接成一个字符串lower(str):将字符串str全部转为小写upper(str):将字符串str全部转为大写lpad(str,n,pad):左填充,将字符串pad对str的左边进行填充,达到n个字符串长度rpad(str,n,......
  • 【安全学习之路】Day34
    ......
  • 2023 杭电多校 Day1
    1009签到,队友哥切的,没看1002\(f(x,0/1/2)\)表示当前点没有覆盖/覆盖/放置观察点子树内最小代价,简单转移即可。f[x][1]=1e18;f[x][2]=a[x];f[x][0]=0;for(inty:e[x])if(y!=fx){ dfs(y,x); statici64g[3]; g[0]=g[1]=g[2]=1e18; g[1]=f[......
  • springBoot 2.7.x整合 swagger2.9
    1.添加依赖<!--swagger--><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version></dep......
  • MySQL
    SQLSQL通用语法SQL语句可以单行或多行书写,以分号结尾。SQL语句可以使用空格/缩进来增强语句可读性。MySQL数据库的SQL语句不区分大小写,关键字建议使用大写。注释单行注释:--注释内容或者#注释内容(MySQL特有)多行注释:/*注释内容*/ DDL-数据库操作查询......
  • odoo editable两种属性的区别
    editable=top时,新增的行出现的第一行,如下图:editable=bottom,,新增的行出现的最后一行,如下图:代码如图:......
  • Vscode Python Workspace 设定流程
    这里记录一下,使用vscode编写一个Python项目时,个人觉得比较舒服的配置方法:预先准备首先保存项目文件夹为工作区,获得xxx.code-workspace文件,以后通过它打开工作区。禁用不需要的插件。Python虚拟环境使用虚拟python环境可以把项目的依赖项安装到项目文件夹下,不会“污......