加载DLL动态库
提示
需使用LoadLibraryA()
命令,加载DLL动态库,才可以正常使用。
其他语言皆是一样,操作命令有所不同而已!
C 示例
#include <iostream>
#include <filesystem>
#include <windows.h>
// 获取当前运行目录
std::filesystem::path current_path = std::filesystem::current_path();
// DLL 路径
std::filesystem::path dll_path = current_path / "EtpBot.dll";
// 加载 DLL
HMODULE hModuleA = LoadLibraryA(dll_path.string().c_str());
if (hModuleA == nullptr) {
DWORD error = GetLastError();
std::cerr << "Failed to load DLL: " << dll_path << std::endl;
std::cerr << "Error code: " << error << std::endl;
return 1;
}
// 定义函数指针
auto TP_创建投屏服务 = (int(__stdcall*)(const char* Path))(GetProcAddress(hModuleA, "TP_创建投屏服务"));
auto TP_销毁投屏服务 = (void(__stdcall*)())(GetProcAddress(hModuleA, "TP_销毁投屏服务"));
auto TP_投屏初始化 = (int(__stdcall*)(const char* Serial))(GetProcAddress(hModuleA, "TP_投屏初始化"));
auto TP_启动投屏 = (int(__stdcall*)(const char* Serial, int Dpi, int Bit, int Fps))(GetProcAddress(hModuleA, "TP_启动投屏"));
auto TP_暂停投屏 = (void(__stdcall*)(const char* Serial, bool Pause))(GetProcAddress(hModuleA, "TP_暂停投屏"));
auto TP_停止投屏 = (void(__stdcall*)(const char* Serial))(GetProcAddress(hModuleA, "TP_停止投屏"));
auto TP_关闭副屏幕 = (void(__stdcall*)(const char* Serial))(GetProcAddress(hModuleA, "TP_关闭副屏幕"));
auto TP_置渲染ID = (void(__stdcall*)(const char* Serial, int ID))(GetProcAddress(hModuleA, "TP_置渲染ID"));
auto TP_置断开回调 = (void(__stdcall*)(const char* Serial, int P))(GetProcAddress(hModuleA, "TP_置断开回调"));
auto TP_置附加参数 = (void(__stdcall*)(const char* Serial, int Parameter))(GetProcAddress(hModuleA, "TP_置附加参数"));
auto TP_置主屏幕场景 = (int(__stdcall*)(const char* Serial, int hWnd, int Width, int high, int Dit, bool Zoom))(GetProcAddress(hModuleA, "TP_置主屏幕场景"));
auto TP_置副屏幕场景 = (int(__stdcall*)(const char* Serial, int hWnd, int Width, int high, int Dit, bool Zoom, bool Sync, int* Himg, int* Wimg))(GetProcAddress(hModuleA, "TP_置副屏幕场景"));
auto TP_模拟按下 = (void(__stdcall*)(const char* Serial, int ID, int x, int y))(GetProcAddress(hModuleA, "TP_模拟按下"));
auto TP_模拟放开 = (void(__stdcall*)(const char* Serial, int ID, int x, int y))(GetProcAddress(hModuleA, "TP_模拟放开"));
auto TP_模拟移动 = (void(__stdcall*)(const char* Serial, int ID, int x, int y))(GetProcAddress(hModuleA, "TP_模拟移动"));
auto TP_模拟滚动 = (void(__stdcall*)(const char* Serial, int x, int y, int r))(GetProcAddress(hModuleA, "TP_模拟滚动"));
auto TP_按键按下 = (void(__stdcall*)(const char* Serial, int keycode, int FN, bool CapsLock))(GetProcAddress(hModuleA, "TP_按键按下"));
auto TP_按键放开 = (void(__stdcall*)(const char* Serial, int keycode, int FN, bool CapsLock))(GetProcAddress(hModuleA, "TP_按键放开"));
auto TP_发送命令 = (void(__stdcall*)(const char* Serial, int Keycode, int Action))(GetProcAddress(hModuleA, "TP_发送命令"));
auto TP_粘贴数据 = (void(__stdcall*)(const char* Serial, const char* str))(GetProcAddress(hModuleA, "TP_粘贴数据"));
auto TP_屏幕息屏 = (void(__stdcall*)(const char* Serial))(GetProcAddress(hModuleA, "TP_屏幕息屏"));
auto TP_屏幕唤醒 = (void(__stdcall*)(const char* Serial))(GetProcAddress(hModuleA, "TP_屏幕唤醒"));
auto TP_下拉通知栏 = (void(__stdcall*)(const char* Serial))(GetProcAddress(hModuleA, "TP_下拉通知栏"));
auto TP_下拉设置栏 = (void(__stdcall*)(const char* Serial))(GetProcAddress(hModuleA, "TP_下拉设置栏"));
auto TP_旋转屏幕 = (void(__stdcall*)(const char* Serial))(GetProcAddress(hModuleA, "TP_旋转屏幕"));
auto TP_更新比特率 = (int(__stdcall*)(const char* Serial, int Bit))(GetProcAddress(hModuleA, "TP_更新比特率"));
auto TP_更新分辨率 = (int(__stdcall*)(const char* Serial, int Dpi))(GetProcAddress(hModuleA, "TP_更新分辨率"));
auto TP_更新帧数 = (int(__stdcall*)(const char* Serial, int Fps))(GetProcAddress(hModuleA, "TP_更新帧数"));
auto TP_更新画面配置 = (int(__stdcall*)(const char* Serial, int Dpi, int Bit, int Fps))(GetProcAddress(hModuleA, "TP_更新画面配置"));
auto TP_更新主屏幕尺寸 = (void(__stdcall*)(const char* Serial, int Width, int high, int Dit))(GetProcAddress(hModuleA, "TP_更新主屏幕尺寸"));
auto TP_更新副屏幕尺寸 = (void(__stdcall*)(const char* Serial, int Width, int high, int Dit))(GetProcAddress(hModuleA, "TP_更新副屏幕尺寸"));
auto TP_保存图片 = (int(__stdcall*)(const char* Serial, const char* Path, int Format, int Quality))(GetProcAddress(hModuleA, "TP_保存图片"));
auto TP_取帧图片数据 = (int*(__stdcall*)(const char* Serial, int Format))(GetProcAddress(hModuleA, "TP_取帧图片数据"));
auto TP_取渲染图片数据 = (int*(__stdcall*)(const char* Serial, int Format))(GetProcAddress(hModuleA, "TP_取渲染图片数据"));
auto TP_取帧宽高 = (int(__stdcall*)(const char* Serial, int* Width, int* high))(GetProcAddress(hModuleA, "TP_取帧宽高"));
auto TP_取渲染宽高 = (int(__stdcall*)(const char* Serial, int* Width, int* high))(GetProcAddress(hModuleA, "TP_取渲染宽高"));
auto TP_取屏幕方向 = (int(__stdcall*)(const char* Serial))(GetProcAddress(hModuleA, "TP_取屏幕方向"));
auto TP_取渲染ID = (int(__stdcall*)(const char* Serial))(GetProcAddress(hModuleA, "TP_取渲染ID"));
auto TP_取附加参数 = (int(__stdcall*)(const char* Serial))(GetProcAddress(hModuleA, "TP_取附加参数"));
auto TP_取错误描述 = (const char* (__stdcall*)(const char* Serial))(GetProcAddress(hModuleA, "TP_取错误描述"));
auto TP_同步剪辑版 = (void(__stdcall*)(const char* Serial, bool Sync))(GetProcAddress(hModuleA, "TP_同步剪辑版"));
auto TP_重画 = (void(__stdcall*)(const char* Serial))(GetProcAddress(hModuleA, "TP_重画"));
auto TP_坐标计算 = (void(__stdcall*)(const char* Serial, int* x, int* y, int W, int H, int D))(GetProcAddress(hModuleA, "TP_坐标计算"));
创建投屏服务
- 函数原型
int __stdcall TP_创建投屏服务 (const char* Path)
- 参数定义
Path
[路径]-- EtpBot.dll 路径
- 返回值
0
成功-1
失败
示例
if ( !TP_创建投屏服务(std::filesystem::current_path().string().c_str())) {
printf("创建服务成功");
return true;
}else{
printf("创建服务失败");
return false;
};
提示
全局命令,请勿重复操作此命令。不使用时,务必要销毁释放资源。
销毁投屏服务
- 函数原型
void __stdcall TP_销毁投屏服务 ()
参数定义
- 无
返回值
- 无
示例
TP_销毁投屏服务();
提示
销毁释放占用资源,所有操作都将无法使用。推荐在软件关闭时使用此命令
投屏初始化
- 函数原型
int __stdcall TP_投屏初始化 (const char* Serial)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取
返回值
0
成功-1
失败
示例
if( !TP_投屏初始化("emulator-5554") ){
printf("初始化成功");
return true;
}else {
printf("初始化失败,错误描述:%s\n", TP_取错误描述("emulator-5554"));
return false;
};
提示
“初始化失败” 可通过命令 "取错误描述" 查看失败原因
注意
投屏初始化基于ADB操作,必须保证ADB已启动,且正常连接设备!
启动投屏
- 函数原型
int __stdcall TP_启动投屏 (const char* Serial, int Dpi, int Bit, int Fps)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Dpi
[分辨率] -- 例 640 720 1080 1280 1920 0原始比例Bit
[比特率] -- 1-100 越高越清晰Fps
[帧数] -- 帧/秒 推荐10-30帧
返回值
0
成功-1
失败
示例
if( !TP_启动投屏("emulator-5554", 720, 20, 20) ){
printf("启动投屏成功");
return true;
}else{
printf("启动投屏失败,错误描述:%s\n", TP_取错误描述("emulator-5554"));
return false;
}
注意
分辨率、比特率、帧数参数数值越高,暂用资源越大,要求电脑配置越高。请谨慎设置。
暂停投屏
- 函数原型
void __stdcall TP_暂停投屏 (const char* Serial, bool Pause)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Pause
[暂停投屏] -- true:暂停投屏 fasle:开启投屏
返回值
- 无
示例
TP_暂停投屏("emulator-5554",true);
提示
根据需求暂停投屏,可降低资源占用
停止投屏
- 函数原型
void __stdcall TP_停止投屏 (const char* Serial)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取
返回值
- 无
示例
TP_停止投屏("emulator-5554");
注意
需要时间处理线程,需给予充足时间
关闭副屏幕
- 函数原型
void __stdcall TP_关闭副屏幕 (const char* Serial)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取
返回值
- 无
示例
TP_关闭副屏幕("emulator-5554");
提示
关闭副屏幕,主屏幕渲染恢复正常
置渲染ID
- 函数原型
void __stdcall TP_置渲染ID (const char* Serial, int ID)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取ID
[自定义序号] --单台设备可不用设置,默认渲染ID为0
返回值
- 无
示例
TP_置渲染ID("emulator-5554", 1);
提示
渲染ID作用于投屏操作多台设备,分配每台设备序号,异常断开回调根据序号处理断开事件。
置断开回调
- 函数原型
void __stdcall TP_置断开回调 (const char* Serial, int P)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取P
[回调地址]参数一: 渲染id
{整数型} -- 与置渲染ID相对应参数二: 错误信息
{字符串} -- 断开错误信息
返回值
- 无
示例
TP_置断开回调("emulator-5554", P*);
置附加参数
- 函数原型
void __stdcall TP_置附加参数 (const char* Serial, int Parameter)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Parameter
[自定义参数] --附加信息
返回值
- 无
示例
TP_置附加参数("emulator-5554", 1001);
置主屏幕场景
- 函数原型
int __stdcall TP_置主屏幕场景 (const char* Serial, int hWnd, int Width, int high, int Dit, bool Zoom)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取hWnd
[句柄] --场景句柄Width
[宽度] --场景宽度high
[高度] --场景高度Dit
[方向] --HOME键方向 0 = 0° (360°) | 1 = 90° | 2 = 180° | 3 = 270°Zoom
[缩放] --根据实际场景高宽进行缩放,缩放可减轻渲染压力
返回值
0
成功-1
失败
示例
if( !TP_置主屏幕场景("emulator-5554", 360, 640, 0, fasle) ){
printf("主场景设置成功");
return true;
}else{
printf("主场景设置失败,错误描述:%s\n", TP_取错误描述("emulator-5554"));
return false;
}
提示
屏幕可360°旋转,旋转方向由下向左旋转,0 90 180 270 360,HOME键为准!
置副屏幕场景
- 函数原型
int __stdcall TP_置副屏幕场景 (const char* Serial, int hWnd, int Width, int high, int Dit, bool Zoom, bool Sync, int* Himg, int* Wimg)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取hWnd
[句柄] --场景句柄Width
[宽度] --场景宽度high
[高度] --场景高度Dit
[方向] --HOME键方向 0 90 180 360Zoom
[缩放] --根据实际场景高宽进行缩放,缩放可减轻渲染压力Sync
[同步] --主副屏幕是否同步Himg
[竖图片] --如果不同步,可设置主屏幕显示图片Wimg
[横图片] --如果不同步,可设置主屏幕显示图片
返回值
0
成功-1
失败
示例
#include <filesystem>
#include <windows.h>
#include <fstream>
//读取文件
std::vector<uint8_t> readFileBytes(const std::string& filePath) {
std::ifstream file(filePath, std::ios::binary | std::ios::ate);
std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg);
std::vector<uint8_t> buffer(size);
file.read(reinterpret_cast<char*>(buffer.data()), size)
return buffer;
}
// 写内存字节集,成功返回内存指针地址,失败返回0
int* WriteByteArray(const std::vector<uint8_t>& data) {
size_t len = data.size();
if (len < 1) {
return nullptr;
}
// 分配内存:4字节长度 + 数据长度
int* ptr = (int*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 4 + len);
if (ptr == nullptr) {
return nullptr;
}
// 写入长度
*ptr = (int)len;
// 写入数据
memcpy(ptr + 1, data.data(), len);
return ptr;
}
//不同步,设置主屏幕显示图片。 也可以不设置,使用默认图片
auto imageData = readFileBytes("D:\\1.png");
int* data = WriteByteArray(imageData);
if (!TP_置副屏幕场景("emulator-5554", 790682, 378, 650, 0, false, false, data, 0)) {
printf("副场景设置成功");
return true;
}
else {
printf("副场景设置失败, 错误描述:%s\n", TP_取错误描述("emulator-5554"));
return false;
};
//同步,无需设置主屏幕显示图片
if( !TP_置副屏幕场景("emulator-5554", 360, 640, 0, fasle, true,0,0)){
printf("副场景设置成功");
return true;
}else{
printf("副场景设置失败,错误描述:%s\n", TP_取错误描述("emulator-5554"));
return false;
}
提示
如设置同步,图片设置无效。
设置不同步,可自定义展示图片,也可输入 0 使用默认图片。
坐标计算
- 函数原型
void __stdcall TP_坐标计算 (const char* Serial,int* x, int* y , int W, int H, int D)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取x
[坐标X] --鼠标坐标Xy
[坐标X] --鼠标坐标XW
[高度] --窗口高度H
[宽度] --窗口宽度D
[方向] --当前渲染方向
返回值
- 无
示例
//如果需要发送手机屏幕实际坐标,组件宽高填写手机分辨率
int x = 115;
int y = 150;
TP_坐标计算 ("emulator-5554", &x, &y, 360, 640, 0);
printf("坐标:%d,%d\n", x, y);
提示
组件方向并非手机HOME键实际方向。 而是组件渲染显示方向
例:手机HOME键向下竖屏,你希望渲染时HOME键向左 90° 横向显示。 那么需要填写:1 ,根据显示方向,计算出实际坐标
模拟按下
- 函数原型
void __stdcall TP_模拟按下 (const char* Serial, int ID, int x, int y)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取ID
[触摸ID] --多指操作使用,如不使用多指操作,可填写 0x
[坐标X]y
[坐标Y]
返回值
- 无
示例
//鼠标在窗口点击的位置,根据窗口宽高方向,计算出手机屏幕实际坐标
//如果需要发送手机屏幕实际坐标,组件宽高填写手机分辨率
int X = 鼠标坐标X;
int Y = 鼠标坐标Y;
G_按下 = true ;
TP_坐标计算 ("emulator-5554", &x, &y, 360, 640, 0);
TP_模拟按下 ("emulator-5554", 0, X, Y)
提示
滑动屏幕需要先按下,在滑动。 所以这里赋值一个变量 "G_按下 = true"给模拟移动做判断
模拟放开
- 函数原型
void __stdcall TP_模拟放开 (const char* Serial, int ID, int x, int y)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取ID
[触摸ID] --多指操作使用,如不使用多指操作,可填写 0x
[坐标X]y
[坐标Y]
返回值
- 无
示例
//鼠标在窗口弹起的位置,根据窗口宽高方向,计算出手机屏幕实际坐标
//如果需要发送手机屏幕实际坐标,组件宽高填写手机分辨率
int X = 鼠标坐标X;
int Y = 鼠标坐标Y;
G_按下 = false ;
TP_坐标计算 ("emulator-5554", &x, &y, 360, 640, 0);
TP_模拟放开 ("emulator-5554", 0, X, Y)
提示
按键放开则无法滑动,所以这里赋值一个变量 "G_按下 = false"给模拟移动做判断
模拟移动
- 函数原型
void __stdcall TP_模拟移动 (const char* Serial, int ID, int x, int y)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取ID
[触摸ID] --多指操作使用,如不使用多指操作,可填写 0x
[坐标X]y
[坐标Y]
返回值
- 无
示例
//鼠标在窗口移动的位置,根据窗口宽高方向,计算出手机屏幕实际坐标
//如果需要发送手机屏幕实际坐标,组件宽高填写手机分辨率
int X = 鼠标坐标X;
int Y = 鼠标坐标Y;
if(G_按下){
TP_坐标计算("emulator-5554", &x, &y, 360, 640, 0);
TP_模拟移动("emulator-5554", 0, X, Y)
}
注意
滑动手机屏幕正常操作,按下-》滑动-》放开, 所以需判断是否按下。
模拟滚动
- 函数原型
void __stdcall TP_模拟滚动 (const char* Serial, int x, int y, int r)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取x
[坐标X] --滚动起始坐标Xy
[坐标Y] --滚动起始坐标Yr
[滚动距离] --滚轮滚动距离 1 或 -1 向上向下滚动
返回值
- 无
示例
//鼠标在窗口的位置,根据窗口宽高方向,计算出手机屏幕实际坐标
//如果需要发送手机屏幕实际坐标,组件宽高填写手机分辨率
//X,Y为滚动起始坐标
int X = 鼠标坐标X;
int Y = 鼠标坐标Y;
TP_坐标计算("emulator-5554", &x, &y, 360, 640, 0);
TP_模拟滚动("emulator-5554", X, Y, -1)
按键按下
- 函数原型
void __stdcall TP_按键按下 (const char* Serial, int keycode, int FN, bool CapsLock)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取keycode
[键码] --键盘键码keyCodeFN
[功能键] --Ctrl Shift Alt等功能键CapsLock
[大小写状态]
返回值
- 无
示例
if(keycode = 20){
if(m_CapsLock){
m_CapsLock = false
}else{
m_CapsLock = true
}
}
if(FN = #Ctrl键 && keycode = #V键){
TP_粘贴数据("emulator-5554", 取剪辑板文本 ())
}
TP_按键按下("emulator-5554", keycode, FN, m_CapsLock)
提示
内部会通过Keycode
键码转换为安卓 Android Keycode
。
按键放开
- 函数原型
void __stdcall TP_按键放开 (const char* Serial, int keycode, int FN, bool CapsLock)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取keycode
[键码] --键盘键码keyCodeFN
[功能键] --Ctrl Shift Alt等功能键CapsLock
[大小写状态]
返回值
- 无
示例
//m_大小写锁:在按键按下时 已赋值真假状态。所以这里不用判断或获取、赋值
TP_按键放开("emulator-5554", keycode, FN, m_CapsLock)
提示
内部会通过Keycode
键码转换为安卓 Android Keycode
。
发送命令
- 函数原型
void __stdcall TP_发送命令 (const char* Serial, int Keycode, int Action)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Keycode
[键码] --Android KeycodeAction
[动作] --0 为按下弹起 1 为按下 2 为弹起
返回值
- 无
示例
//单击 HOME 键
TP_发送命令("emulator-5554", 3, 0)
keycode | 含义 |
---|---|
3 | HOME 键 |
4 | 返回键 |
5 | 打开拨号应用 |
6 | 挂断电话 |
24 | 增加音量 |
25 | 降低音量 |
26 | 电源键 |
27 | 拍照(需要在相机应用里) |
64 | 打开浏览器 |
82 | 菜单键 |
85 | 播放/暂停 |
86 | 停止播放 |
87 | 播放下一首 |
88 | 播放上一首 |
122 | 移动光标到行首或列表顶部 |
123 | 移动光标到行末或列表底部 |
126 | 恢复播放 |
127 | 暂停播放 |
164 | 静音 |
176 | 打开系统设置 |
187 | 切换应用 |
207 | 打开联系人 |
208 | 打开日历 |
209 | 打开音乐 |
210 | 打开计算器 |
220 | 降低屏幕亮度 |
221 | 提高屏幕亮度 |
223 | 系统休眠 |
224 | 点亮屏幕 |
231 | 打开语音助手 |
276 | 如果没有 wakelock 则让系统休眠 |
粘贴数据
- 函数原型
void __stdcall TP_粘贴数据 (const char* Serial, const char* str)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取str
[文本数据] --发送粘贴文本
返回值
- 无
示例
TP_粘贴数据("emulator-5554", TP_取剪辑版内容())
推荐
粘贴命令放在按下事件里
屏幕息屏
- 函数原型
void __stdcall TP_屏幕息屏 (const char* Serial)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取
返回值
- 无
示例
TP_屏幕息屏("emulator-5554")
注意
手机屏幕休眠,投屏不休眠。部分手机型号不支持!
屏幕唤醒
- 函数原型
void __stdcall TP_屏幕唤醒 (const char* Serial)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取
返回值
- 无
示例
TP_屏幕唤醒("emulator-5554")
注意
手机屏幕休眠,投屏不休眠。部分手机型号不支持!
下拉通知栏
- 函数原型
void __stdcall TP_下拉通知栏 (const char* Serial)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取
返回值
- 无
示例
TP_下拉通知栏("emulator-5554")
下拉设置栏
- 函数原型
void __stdcall TP_下拉设置栏 (const char* Serial)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取
返回值
- 无
示例
TP_下拉设置栏("emulator-5554")
旋转屏幕
- 函数原型
void __stdcall TP_旋转屏幕 (const char* Serial)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取
返回值
- 无
示例
TP_旋转屏幕("emulator-5554")
注意
改变屏幕状态 部分手机不支持
更新比特率
- 函数原型
int __stdcall TP_更新比特率 (const char* Serial, int Bit)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Bit
[比特率] --1-100 越高越清晰
返回值
0
成功-1
失败
示例
if (!TP_更新比特率("emulator-5554", 20)) {
printf("更新成功");
return true;
}
else {
printf("更新失败,错误描述:%s\n", TP_取错误描述("emulator-5554"));
return false;
};
注意
更新需要时间,请给予充足时间等待
内部并没有处理事件,不推荐在主线程下使用,防止卡顿。
更新分辨率
- 函数原型
int __stdcall TP_更新分辨率 (const char* Serial, int Dpi)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Dpi
[分辨率] --例 640 720 1080 1280 1920 0=原始画面
返回值
0
成功-1
失败
示例
if (!TP_更新分辨率("emulator-5554", 720)) {
printf("更新成功");
return true;
}
else {
printf("更新失败,错误描述:%s\n", TP_取错误描述("emulator-5554"));
return false;
};
注意
更新需要时间,请给予充足时间等待
内部并没有处理事件,不推荐在主线程下使用,防止卡顿。
更新帧数
- 函数原型
int __stdcall TP_更新帧数 (const char* Serial, int Fps)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Fps
[帧率] --帧/秒 推荐10-30帧 最大60
返回值
0
成功-1
失败
示例
if (!TP_更新帧数("emulator-5554", 20)) {
printf("更新成功");
return true;
}
else {
printf("更新失败,错误描述:%s\n", TP_取错误描述("emulator-5554"));
return false;
};
注意
更新需要时间,请给予充足时间等待
内部并没有处理事件,不推荐在主线程下使用,防止卡顿。
更新画面配置
- 函数原型
int __stdcall TP_更新画面配置 (const char* Serial, int Dpi, int Bit, int Fps)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Dpi
[分辨率] --例 640 720 1080 1280 1920 0=原始画面Bit
[比特率] --1-100 越高越清晰Fps
[帧率] --帧/秒 推荐10-30帧 最大60
返回值
0
成功-1
失败
示例
if (!TP_更新画面配置("emulator-5554", 720, 40, 20)) {
printf("更新成功");
return true;
}
else {
printf("更新失败,错误描述:%s\n", TP_取错误描述("emulator-5554"));
return false;
};
注意
更新需要时间,请给予充足时间等待
内部并没有处理事件,不推荐在主线程下使用,防止卡顿。
更新主屏幕尺寸
- 函数原型
void __stdcall TP_更新主屏幕尺寸 (const char* Serial, int Width, int high, int Dit)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Width
[场景宽] --新宽度high
[场景高] --新高度Dit
[场景方向] --HOME键方向 0 90 180 360
返回值
- 无
示例
TP_更新主屏幕尺寸("emulator-5554", 640, 960, 0)
注意
组件尺寸有变化,及时更新尺寸,防止渲染出错。
内部并没有处理事件,不推荐在主线程下使用,防止卡顿。
更新副屏幕尺寸
- 函数原型
void __stdcall TP_更新副屏幕尺寸 (const char* Serial, int Width, int high, int Dit)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Width
[场景宽] --新宽度high
[场景高] --新高度Dit
[场景方向] --HOME键方向 0 90 180 360
返回值
- 无
示例
TP_更新副屏幕尺寸("emulator-5554", 640, 960, 0)
注意
组件尺寸有变化,及时更新尺寸,防止渲染出错。
内部并没有处理事件,不推荐在主线程下使用,防止卡顿。
保存图片
- 函数原型
int __stdcall TP_保存图片 (const char* Serial, const char* Path, int Format, int Quality)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Path
[路径] --图片保存路径,尽量不要有中文和空格Format
[格式] --0 - PNG 1 - BMPQuality
[质量] --1-100 越高越清晰 图片越大
返回值
0
成功-1
失败
示例
if (!TP_保存图片("emulator-5554", "D:\11.png", 0, 60)) {
printf("保存成功");
return true;
}
else {
printf("保存失败,错误描述:%s\n", TP_取错误描述("emulator-5554"));
return false;
};
取帧图片数据
- 函数原型
int* __stdcall TP_取帧图片数据 (const char* Serial, int Format)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Format
[格式] --0 - PNG 1 - BMP
返回值
ptr
内存地址nullptr
错误
示例
#include <filesystem>
#include <windows.h>
#include <fstream>
//写入文件
bool writeBinaryData(const std::string& filePath, const void* data, size_t size) {
if (size<1) {
return false;
}
std::ofstream outFile(filePath, std::ios::binary);
if (!outFile) {
return false;
}
outFile.write(static_cast<const char*>(data), size);
if (!outFile) {
return false;
}
outFile.close();
return true;
}
// 读内存字节集,成功返回预先保存的字节集数据
std::vector<uint8_t> ReadByteArray(int* ptr, bool freeMemory = true) {
std::vector<uint8_t> result;
if (ptr == nullptr) {
return result;
}
int len = *ptr;
if (len < 1) {
return result;
}
result.resize(len);
memcpy(result.data(), ptr + 1, len);
if (freeMemory) {
HeapFree(GetProcessHeap(), 0, ptr);
}
return result;
}
int* ptr = TP_取帧图片数据("emulator-5554", 1);
std::vector<uint8_t> readData = ReadByteArray(ptr);
if (writeBinaryData("D:\\2.png", readData.data(), readData.size())) {
printf("图片已保存至:D:\\2.png");
}else{
printf("图片保存失败");
}
注意
解码器取出一帧H264数据 ,不支持多线程取图
取渲染图片数据
- 函数原型
int __stdcall TP_取渲染图片数据 (const char* Serial, int Format)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Format
[格式] -- 0 - PNG 1 - JPG 2 - BMP
返回值
ptr
内存地址nullptr
错误
示例
#include <filesystem>
#include <windows.h>
#include <fstream>
//写入文件
bool writeBinaryData(const std::string& filePath, const void* data, size_t size) {
if (size < 1) {
return false;
}
std::ofstream outFile(filePath, std::ios::binary);
if (!outFile) {
return false;
}
outFile.write(static_cast<const char*>(data), size);
if (!outFile) {
return false;
}
outFile.close();
return true;
}
// 读内存字节集,成功返回预先保存的字节集数据
std::vector<uint8_t> ReadByteArray(int* ptr, bool freeMemory = true) {
std::vector<uint8_t> result;
if (ptr == nullptr) {
return result;
}
int len = *ptr;
if (len < 1) {
return result;
}
result.resize(len);
memcpy(result.data(), ptr + 1, len);
if (freeMemory) {
HeapFree(GetProcessHeap(), 0, ptr);
}
return result;
}
int* ptr = TP_取渲染图片数据("emulator-5554", 1);
std::vector<uint8_t> readData = ReadByteArray(ptr);
if (writeBinaryData("D:\\2.png", readData.data(), readData.size())) {
printf("图片已保存至:D:\\2.png");
}else{
printf("图片保存失败");
}
注意
渲染器取出一帧数据 , 支持多线程取图
取帧宽高
- 函数原型
int __stdcall TP_取帧宽高 (const char* Serial, int* Width, int* high)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Width
[宽度] --图片宽度 指针high
[高度] --图片高度 指针
返回值
0
成功-1
失败
示例
int w, h;
TP_取帧宽高("emulator-5554", &w, &h);
printf("宽度:%d\n", w);
printf("高度:%d\n", h);
解码器取出一帧H264数据的宽高
取渲染宽高
- 函数原型
int __stdcall TP_取渲染宽高 (const char* Serial, int* Width, int* high)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Width
[宽度] --图片宽度 指针high
[高度] --图片高度 指针
返回值
0
成功-1
失败
示例
int w, h;
TP_取渲染宽高("emulator-5554", &w, &h);
printf("宽度:%d\n", w);
printf("高度:%d\n", h);
渲染器取出一帧宽高
取屏幕方向
- 函数原型
int __stdcall TP_取屏幕方向 (const char* Serial)
- 参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取
- 返回值
1
竖屏2
横屏-1
失败
示例
int Dit = TP_取屏幕方向("emulator-5554")
if(Dit = 1){
printf("竖屏方向");
}
if(Dit = 2){
printf("横屏方向”);
}
取渲染ID
- 函数原型
int __stdcall TP_取渲染ID (const char* Serial)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取
返回值
-1
失败
示例
int ID = TP_取渲染ID("emulator-5554")
取附加参数
- 函数原型
int __stdcall TP_取附加参数 (const char* Serial)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取
返回值
-1
失败
示例
TP_取附加参数("emulator-5554")
取错误描述
- 函数原型
const char* __stdcall TP_取错误描述 (const char* Serial)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取
返回值
- 错误描述
示例
TP_取错误描述("emulator-5554")
提示
如果命令执行失败,可通过此命令查看错误描述
同步剪辑版
- 函数原型
void __stdcall TP_同步剪辑版 (const char* Serial, bool Sync)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取Sync
[是否同步] -- 是否与手机同步剪辑版,默认不同步
返回值
- 无
示例
TP_同步剪辑版("emulator-5554", true);
重画
- 函数原型
void __stdcall TP_重画 (const char* Serial)
参数定义
Serial
[设备标识] --手机设备标识符 ADB命令获取
返回值
- 无
示例
TP_重画("emulator-5554");
提示
推荐窗口 WM_PAINT消息 重画