一.API跨语言平台支持
鼠标轨迹API 底层实现采用 C/C++ 语言,利用其高性能和系统级访问能力,开发出高效的鼠标轨迹模拟算法。通过将算法封装为 DLL(动态链接库),可以方便地在不同的编程环境中调用,实现跨语言的兼容性。
通过 DLL 封装,开发者可以在 C++、Python、易语言、按键精灵等多种编程语言中使用鼠标轨迹模拟技术。这种封装方式提供了一种简便的接口,使得不同背景的开发者都能够轻松集成和使用这一技术。
二.鼠标轨迹 Demo 效果演示
- 1.开始坐标为(100,100),结束坐标为(800,800),通过调用接口获得 4 条鼠标轨迹
- 2.开始坐标为(1000,100),结束坐标为(800,800),通过调用接口获得 2 条鼠标轨迹
三.C++鼠标轨迹 Demo 下载
百度云盘下载
夸克云盘下载
123云盘下载
四.C++代码演示
1.头文件
// Copyright (c) 2024
//
// 保留所有权利。
//
// 在满足以下条件的情况下,允许重新使用和分发:
//
// 1. 代码必须保留上述版权声明、作者声明和/或最初发布的网址。
// 2. 不得将代码用于商业目的,除非与版权所有者签订了书面协议。
// 3. 修改过的源版本必须清楚地标识出修改的部分,并且不得以任何方式表明版权所有者支持或认可这些修改。
//
#ifndef SN_SDK_H_
#define SN_SDK_H_
#include <windows.h>
//返回参数
typedef struct SN_RESULT {
int code; //错误码,如果为 0 表示成功,否则表示错误号
char message[4096]; //错误信息,如果为 "OK" 表示成功,否则返回错误信息
}SN_RESULT;
//坐标参数
typedef struct SN_POINT
{
int x; //屏幕坐标,左上角(0,0),右下角(1920,1080 - 以实际屏幕为准)
int y; //屏幕坐标,左上角(0,0),右下角(1920,1080 - 以实际屏幕为准)
}SN_POINT;
//轨迹参数
typedef struct SN_POINT_PARAMS
{
struct SN_POINT point;//屏幕坐标,左上角(0,0),右下角(1920,1080 - 以实际屏幕为准)
int delayTime; //延时时间(单位:毫秒),仅供参考
}SN_POINT_PARAMS;
/创建句柄
* 参数:
* [in] szKey: 卡密(购买卡密:https://shop.4yuns.com/links/7C9F16B7)
* [in] pOnnxFilePath:设置 onnx 模型文件路径,如果设置为 NULL,默认和 DLL文件同级目录
* [out] pResult: 返回错误信息,参数pResult.code(错误码)如果为 0 表示成功,否则表示错误号;
返回值:成功返回句柄,失败返回NULL
/
HANDLE WINAPI apiSNCreateHandle(char* szKey, char* pOnnxFilePath, SN_RESULT* pResult);
/获取鼠标移动轨迹
* 参数:
* [in] handle: 句柄(通过调用apiSNCreateHandle得到)
* [in] startPoint: 开始坐标,左上角(0,0),右下角(1920,1080 - 以实际屏幕为准)
* [in] endPoint: 结束坐标,左上角(0,0),右下角(1920,1080 - 以实际屏幕为准)
* [out] points: 轨迹数组,如果数组中元素 point 出现(-1,-1),表示鼠标轨迹结束
返回值:返回参数SN_RESULT.code(错误码)如果为 0 表示成功,否则表示错误号;
/
SN_RESULT WINAPI apiSNMouseMove(HANDLE handle, SN_POINT startPoint, SN_POINT endPoint, SN_POINT_PARAMS* points);
/获取版本号
* 参数:
* [in] handle: 句柄(通过调用apiSNCreateHandle得到)
* [out] szVersion: 版本号
返回值:返回参数SN_RESULT.code(错误码)如果为 0 表示成功,否则表示错误号;
/
SN_RESULT WINAPI apiSNGetVersion(HANDLE handle, char* szVersion);
/获取错误信息
* 参数:
* [in] handle: 句柄(通过调用apiSNCreateHandle得到)
返回值:返回参数SN_RESULT.code(错误码)如果为 0 表示成功,否则表示错误号;
/
SN_RESULT WINAPI apiSNGetError(HANDLE handle);
/释放句柄(内存)
* 参数:
* [in] handle: 句柄(通过调用apiSNCreateHandle得到)
返回值:返回参数SN_RESULT.code(错误码)如果为 0 表示成功,否则表示错误号;
/
SN_RESULT WINAPI apiSNDestroyHandle(HANDLE handle);
#endif // !SN_SDK_H_
2.CPP文件
//
@SDK功能描述:鼠标轨迹
//
//
#include <iostream>
#include "include/SNSDK.h"
#pragma comment(lib,"./dll/x86/SNSDK.lib")
int main()
{
SN_RESULT pResult = { 0 };
char pKey = (char)"SNKJaURwbfuhcaQaCMJVhdByPZMVsZdqRUMjfWrxY1A5";
//1.创建句柄
HANDLE pHandle = apiSNCreateHandle(pKey,&pResult);
if (!pHandle)
{
printf("error code:%d message:%s \n",pResult.code,pResult.message);
return -LINE;
}
//2.获取轨迹
SN_POINT startPoint = { 100,100 }; //开始坐标
SN_POINT endPoint = { 800,800 }; //结束坐标
SN_POINT_PARAMS track[4096] = { 0 };//轨迹
pResult = apiSNMouseMove(pHandle, startPoint, endPoint, track);
if (pResult.code != 0)
{
printf("error code:%d message:%s \n", pResult.code, pResult.message);
return -LINE;
}
//3.鼠标根据轨迹移动,轨迹最后一个点(-1,-1)
for (int i = 0; i < 4096; i++)
{
struct SN_POINT point = track[i].point;
if (point.x <= 0 && point.y <= 0)//轨迹最后一个点(-1,-1)
break;
printf("x:%d y:%d delay_time:%d \n", point.x, point.y, track[i].delayTime);
}
//4.释放内存
pResult = apiSNDestroyHandle(pHandle);
return 1;
}
/
x:100 y:100 delay_time:0
x:100 y:98 delay_time:10
x:103 y:98 delay_time:15
x:111 y:98 delay_time:16
x:116 y:101 delay_time:15
x:122 y:104 delay_time:2
x:129 y:107 delay_time:13
x:135 y:109 delay_time:2
x:144 y:112 delay_time:14
x:155 y:117 delay_time:2
x:167 y:123 delay_time:14
x:180 y:128 delay_time:2
x:193 y:134 delay_time:13
x:209 y:138 delay_time:2
x:225 y:144 delay_time:13
x:238 y:149 delay_time:5
x:254 y:157 delay_time:10
x:269 y:162 delay_time:5
x:282 y:168 delay_time:11
x:298 y:175 delay_time:5
x:311 y:180 delay_time:10
x:326 y:185 delay_time:6
x:341 y:193 delay_time:9
x:369 y:211 delay_time:15
x:396 y:231 delay_time:16
x:419 y:251 delay_time:16
x:442 y:270 delay_time:16
x:461 y:285 delay_time:17
x:481 y:300 delay_time:15
x:491 y:311 delay_time:15
x:502 y:319 delay_time:2
x:513 y:329 delay_time:14
x:523 y:343 delay_time:2
x:535 y:355 delay_time:14
x:546 y:369 delay_time:0
x:558 y:383 delay_time:15
x:570 y:397 delay_time:2
x:582 y:411 delay_time:13
x:596 y:427 delay_time:2
x:608 y:443 delay_time:14
x:620 y:459 delay_time:5
x:633 y:476 delay_time:10
x:645 y:490 delay_time:5
x:656 y:503 delay_time:11
x:666 y:515 delay_time:5
x:675 y:527 delay_time:11
x:684 y:538 delay_time:5
x:694 y:551 delay_time:11
x:702 y:565 delay_time:5
x:710 y:577 delay_time:11
x:716 y:588 delay_time:5
x:723 y:598 delay_time:11
x:728 y:606 delay_time:5
x:733 y:615 delay_time:11
x:738 y:622 delay_time:5
x:743 y:631 delay_time:11
x:747 y:637 delay_time:5
x:750 y:644 delay_time:11
x:753 y:652 delay_time:5
x:756 y:659 delay_time:10
x:759 y:666 delay_time:5
x:761 y:673 delay_time:11
x:764 y:680 delay_time:5
x:766 y:687 delay_time:11
x:768 y:694 delay_time:5
x:769 y:701 delay_time:10
x:771 y:708 delay_time:5
x:772 y:714 delay_time:11
x:773 y:722 delay_time:5
x:774 y:729 delay_time:10
x:777 y:743 delay_time:16
x:778 y:755 delay_time:15
x:778 y:764 delay_time:16
x:780 y:775 delay_time:16
x:781 y:784 delay_time:16
x:781 y:785 delay_time:15
x:781 y:789 delay_time:2
x:781 y:790 delay_time:13
x:781 y:792 delay_time:2
x:782 y:796 delay_time:14
x:782 y:796 delay_time:2
x:782 y:797 delay_time:14
x:782 y:798 delay_time:15
x:782 y:800 delay_time:311
x:784 y:800 delay_time:16
x:784 y:800 delay_time:5
x:785 y:800 delay_time:10
x:786 y:800 delay_time:5
x:786 y:800 delay_time:11
x:788 y:800 delay_time:6
x:789 y:800 delay_time:9
x:790 y:800 delay_time:5
x:791 y:800 delay_time:10
x:793 y:800 delay_time:16
x:795 y:800 delay_time:16
x:796 y:800 delay_time:15
x:797 y:800 delay_time:15
x:797 y:800 delay_time:2
x:798 y:800 delay_time:15
x:798 y:800 delay_time:30
x:799 y:800 delay_time:15
x:799 y:800 delay_time:15
/