一.鼠标轨迹算法简介
鼠标轨迹底层实现采用 C / C++语言,利用其高性能和系统级访问能力,开发出高效的鼠标轨迹模拟算法。通过将算法封装为 DLL(动态链接库),可以方便地在不同的编程环境中调用,实现跨语言的兼容性。
通过 DLL 封装,开发者可以在 C++、Python、易语言、按键精灵等多种编程语言中使用鼠标轨迹模拟技术。这种封装方式提供了一种简便的接口,使得不同背景的开发者都能够轻松集成和使用这一技术。
二.鼠标轨迹算法支持多种编程语言
目前 Demo支持的编程语言有 C 语言、C++、Python , 易语言、按键精灵等多种编程语言对接还在开发中,当然如果有开发者愿意对接提供 demo,将不胜感激(可以提供报酬)
三.鼠标轨迹算法优势
- 1.模拟人工轨迹(非贝塞尔,一般也画不出来圆滑的贝塞尔曲线)
- 2.适当的停顿/加速/减速
- 3.随机轨迹(固定两个点,每次调用接口可获得不同的随机轨迹)
四.鼠标轨迹算法应用场景
某些软件或游戏可能通过检测异常的鼠标操作来防止作弊,以下为常用场景
- 1.游戏自动化脚本
- 2.滑块拖动轨迹
五.C/C++ 接口调用演示代码
1.头文件
/******************************************************************************************/
@SDK功能描述:C++鼠标轨迹
/******************************************************************************************/
#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)
* [out] pResult: 返回错误信息,参数pResult.code(错误码)如果为 0 表示成功,否则表示错误号;
*
* 返回值:成功返回句柄,失败返回NULL
*
*/
HANDLE WINAPI apiSNCreateHandle(char* szKey, 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
*/