B2B网络软件

标题: AIWROK软件滑动方法集合示例 [打印本页]

作者: YYPOST群发软件    时间: 昨天 08:58
标题: AIWROK软件滑动方法集合示例
AIWROK软件滑动方法集合示例
AIWROK软件滑动方法集合示例 B2B网络软件

AIWROK软件滑动方法集合示例 B2B网络软件

  1. // 滑动方法集合示例
  2. // 该脚本集合了各种滑动方法,并包含找图功能示例
  3. //🍎交流QQ群711841924群一,苹果内测群,528816639

  4. // ==================== 1. 基础滑动方法 ====================

  5. /**
  6. * 基础滑动方法
  7. * @param {number} startX - 起始X坐标
  8. * @param {number} startY - 起始Y坐标
  9. * @param {number} endX - 结束X坐标
  10. * @param {number} endY - 结束Y坐标
  11. * @param {number} duration - 滑动持续时间(毫秒)
  12. */
  13. function basicSwipe(startX, startY, endX, endY, duration) {
  14.     try {
  15.         console.log("执行基础滑动: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ") 持续" + duration + "ms");
  16.         
  17.         // 优先使用auto.swip(根据日志显示这个方法可用)
  18.         if (typeof auto !== 'undefined' && typeof auto.swip === 'function') {
  19.             console.log("使用auto.swip方法");
  20.             auto.swip(startX, startY, endX, endY, duration, 0);
  21.             return true;
  22.         }
  23.         // 尝试使用swipe方法
  24.         else if (typeof swipe !== 'undefined') {
  25.             console.log("使用swipe方法");
  26.             swipe(startX, startY, endX, endY, duration);
  27.             return true;
  28.         }
  29.         // 尝试使用touch.swipe方法
  30.         else if (typeof touch !== 'undefined' && typeof touch.swipe === 'function') {
  31.             console.log("使用touch.swipe方法");
  32.             touch.swipe(startX, startY, endX, endY, duration);
  33.             return true;
  34.         }
  35.         // 尝试使用HID滑动方法
  36.         else if (typeof hid !== 'undefined' && typeof hid.swip === 'function') {
  37.             console.log("使用hid.swip方法");
  38.             hid.swip(startX, startY, endX, endY, 10, duration, 0);
  39.             return true;
  40.         }
  41.         // 尝试使用手势滑动
  42.         else if (typeof auto !== 'undefined' && typeof auto.dispatchGesture === 'function') {
  43.             console.log("使用auto.dispatchGesture方法");
  44.             var points = [[startX, startY], [endX, endY]];
  45.             auto.dispatchGesture(points, duration);
  46.             return true;
  47.         }
  48.         else {
  49.             console.log("❌ 未找到可用的滑动方法");
  50.             return false;
  51.         }
  52.     } catch (e) {
  53.         console.log("❌ 基础滑动失败: " + e);
  54.         return false;
  55.     }
  56. }

  57. // ==================== 2. 百分比坐标滑动 ====================

  58. /**
  59. * 获取屏幕尺寸
  60. * @returns {Object} 包含width和height的对象
  61. */
  62. function getScreenSize() {
  63.     var width = 1080;
  64.     var height = 1920;
  65.    
  66.     try {
  67.         if (typeof screen !== 'undefined') {
  68.             if (typeof screen.getScreenWidth === 'function') {
  69.                 width = screen.getScreenWidth();
  70.             }
  71.             if (typeof screen.getScreenHeight === 'function') {
  72.                 height = screen.getScreenHeight();
  73.             }
  74.         } else if (typeof device !== 'undefined') {
  75.             if (typeof device.width === 'number') {
  76.                 width = device.width;
  77.             }
  78.             if (typeof device.height === 'number') {
  79.                 height = device.height;
  80.             }
  81.         }
  82.     } catch (e) {
  83.         console.log("❌ 获取屏幕尺寸失败: " + e);
  84.     }
  85.    
  86.     return { width: width, height: height };
  87. }

  88. /**
  89. * 百分比坐标滑动
  90. * @param {number} startXPercent - 起始X百分比 (0-1)
  91. * @param {number} startYPercent - 起始Y百分比 (0-1)
  92. * @param {number} endXPercent - 结束X百分比 (0-1)
  93. * @param {number} endYPercent - 结束Y百分比 (0-1)
  94. * @param {number} duration - 滑动持续时间(毫秒)
  95. */
  96. function swipeWithPercentCoordinates(startXPercent, startYPercent, endXPercent, endYPercent, duration) {
  97.     try {
  98.         var screenSize = getScreenSize();
  99.         var startX = Math.round(screenSize.width * startXPercent);
  100.         var startY = Math.round(screenSize.height * startYPercent);
  101.         var endX = Math.round(screenSize.width * endXPercent);
  102.         var endY = Math.round(screenSize.height * endYPercent);
  103.         
  104.         console.log("执行百分比坐标滑动: " +
  105.                (startXPercent * 100).toFixed(0) + "%x" + (startYPercent * 100).toFixed(0) + "% -> " +
  106.                (endXPercent * 100).toFixed(0) + "%x" + (endYPercent * 100).toFixed(0) + "% 持续" + duration + "ms");
  107.         
  108.         return basicSwipe(startX, startY, endX, endY, duration);
  109.     } catch (e) {
  110.         console.log("❌ 百分比坐标滑动失败: " + e);
  111.         return false;
  112.     }
  113. }

  114. // ==================== 3. HID滑动方法 ====================

  115. /**
  116. * HID滑动方法
  117. * @param {number} startX - 起始X坐标
  118. * @param {number} startY - 起始Y坐标
  119. * @param {number} endX - 结束X坐标
  120. * @param {number} endY - 结束Y坐标
  121. * @param {number} steps - 滑动步数
  122. * @param {number} duration - 滑动持续时间(毫秒)
  123. * @param {number} direction - 滑动方向
  124. */
  125. function hidSwipe(startX, startY, endX, endY, steps, duration, direction) {
  126.     try {
  127.         if (typeof hid !== 'undefined' && typeof hid.swip === 'function') {
  128.             console.log("执行HID滑动: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ") 步数:" + steps + " 持续" + duration + "ms");
  129.             hid.swip(startX, startY, endX, endY, steps, duration, direction);
  130.             return true;
  131.         } else {
  132.             console.log("❌ HID模块不可用");
  133.             return false;
  134.         }
  135.     } catch (e) {
  136.         console.log("❌ HID滑动失败: " + e);
  137.         return false;
  138.     }
  139. }

  140. /**
  141. * HID AI智能滑动
  142. * @param {number} startX - 起始X坐标
  143. * @param {number} startY - 起始Y坐标
  144. * @param {number} endX - 结束X坐标
  145. * @param {number} endY - 结束Y坐标
  146. */
  147. function hidSwipeAI(startX, startY, endX, endY) {
  148.     try {
  149.         if (typeof hid !== 'undefined' && typeof hid.swipAI === 'function') {
  150.             console.log("执行HID AI智能滑动: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ")");
  151.             hid.swipAI(startX, startY, endX, endY);
  152.             return true;
  153.         } else {
  154.             console.log("❌ HID模块或swipAI方法不可用");
  155.             return false;
  156.         }
  157.     } catch (e) {
  158.         console.log("❌ HID AI滑动失败: " + e);
  159.         return false;
  160.     }
  161. }

  162. /**
  163. * HID 鼠标滑动
  164. * @param {number} startX - 起始X坐标
  165. * @param {number} startY - 起始Y坐标
  166. * @param {number} endX - 结束X坐标
  167. * @param {number} endY - 结束Y坐标
  168. * @param {number} duration - 滑动持续时间(毫秒)
  169. */
  170. function hidMouseSwipe(startX, startY, endX, endY, duration) {
  171.     try {
  172.         if (typeof hid !== 'undefined' && typeof hid.mouseSwip === 'function') {
  173.             console.log("执行HID鼠标滑动: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ") 持续" + duration + "ms");
  174.             hid.mouseSwip(startX, startY, endX, endY, duration);
  175.             return true;
  176.         } else {
  177.             console.log("❌ HID模块或mouseSwip方法不可用");
  178.             return false;
  179.         }
  180.     } catch (e) {
  181.         console.log("❌ HID鼠标滑动失败: " + e);
  182.         return false;
  183.     }
  184. }

  185. /**
  186. * HID 滑动增强版
  187. * @param {number} startX - 起始X坐标
  188. * @param {number} startY - 起始Y坐标
  189. * @param {number} endX - 结束X坐标
  190. * @param {number} endY - 结束Y坐标
  191. * @param {number} duration - 滑动持续时间(毫秒)
  192. */
  193. function hidSwipeEx(startX, startY, endX, endY, duration) {
  194.     try {
  195.         if (typeof hid !== 'undefined' && typeof hid.swipEx === 'function') {
  196.             console.log("执行HID滑动增强版: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ") 持续" + duration + "ms");
  197.             hid.swipEx(startX, startY, endX, endY, duration);
  198.             return true;
  199.         } else {
  200.             console.log("❌ HID模块或swipEx方法不可用");
  201.             return false;
  202.         }
  203.     } catch (e) {
  204.         console.log("❌ HID滑动增强版失败: " + e);
  205.         return false;
  206.     }
  207. }

  208. /**
  209. * HID 快速滑动
  210. * @param {number} startX - 起始X坐标
  211. * @param {number} startY - 起始Y坐标
  212. * @param {number} endX - 结束X坐标
  213. * @param {number} endY - 结束Y坐标
  214. */
  215. function hidSwipeM(startX, startY, endX, endY) {
  216.     try {
  217.         if (typeof hid !== 'undefined' && typeof hid.swipM === 'function') {
  218.             console.log("执行HID快速滑动: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ")");
  219.             hid.swipM(startX, startY, endX, endY);
  220.             return true;
  221.         } else {
  222.             console.log("❌ HID模块或swipM方法不可用");
  223.             return false;
  224.         }
  225.     } catch (e) {
  226.         console.log("❌ HID快速滑动失败: " + e);
  227.         return false;
  228.     }
  229. }

  230. /**
  231. * HID 多段滑动
  232. * @param {Array} points - 坐标点数组 [[x1,y1],[x2,y2],...]
  233. * @param {number} duration - 滑动持续时间(毫秒)
  234. */
  235. function hidSwipeMultiple(points, duration) {
  236.     try {
  237.         if (typeof hid !== 'undefined' && typeof hid.swipMultiple === 'function') {
  238.             console.log("执行HID多段滑动: " + points.length + "个点 持续" + duration + "ms");
  239.             hid.swipMultiple(points, duration);
  240.             return true;
  241.         } else {
  242.             console.log("❌ HID模块或swipMultiple方法不可用");
  243.             return false;
  244.         }
  245.     } catch (e) {
  246.         console.log("❌ HID多段滑动失败: " + e);
  247.         return false;
  248.     }
  249. }

  250. /**
  251. * 安卓自动化 百分比坐标滑动2.0
  252. * @param {number} startX - 起始X百分比
  253. * @param {number} startY - 起始Y百分比
  254. * @param {number} endX - 结束X百分比
  255. * @param {number} endY - 结束Y百分比
  256. * @param {number} duration - 滑动持续时间(毫秒)
  257. * @param {number} steps - 滑动步数
  258. */
  259. function autoSwipePercentV2(startX, startY, endX, endY, duration, steps) {
  260.     try {
  261.         if (typeof auto !== 'undefined' && typeof auto.swipPercent_v2 === 'function') {
  262.             console.log("执行安卓自动化百分比坐标滑动2.0: " + startX + "%x" + startY + "% -> " + endX + "%x" + endY + "% 持续" + duration + "ms 步数:" + steps);
  263.             auto.swipPercent_v2(startX, startY, endX, endY, duration, steps);
  264.             return true;
  265.         } else {
  266.             console.log("❌ 安卓自动化模块或swipPercent_v2方法不可用");
  267.             return false;
  268.         }
  269.     } catch (e) {
  270.         console.log("❌ 安卓自动化百分比坐标滑动2.0失败: " + e);
  271.         return false;
  272.     }
  273. }

  274. /**
  275. * 路径滑动示例
  276. * 使用path对象创建滑动轨迹
  277. */
  278. function pathSwipeExample() {
  279.     try {
  280.         if (typeof path !== 'undefined') {
  281.             console.log("执行路径滑动示例");
  282.             
  283.             // 定义滑动轨迹
  284.             var p1 = new path();
  285.             // 设置滑动时间
  286.             p1.setDurTime(600);
  287.             // 添加起点
  288.             p1.addPoint(100, 100);
  289.             // 再添加一个点
  290.             p1.addPoint(500, 100);
  291.             // 还可以继续添加点 形成一个轨迹
  292.             p1.addPoint(800, 200);
  293.             
  294.             // 执行手势滑动
  295.             if (typeof auto !== 'undefined' && typeof auto.dispatchGesture === 'function') {
  296.                 auto.dispatchGesture([p1]);
  297.                 console.log("路径滑动执行成功");
  298.                 return true;
  299.             } else {
  300.                 console.log("❌ 安卓自动化模块或dispatchGesture方法不可用");
  301.                 return false;
  302.             }
  303.         } else {
  304.             console.log("❌ path模块不可用");
  305.             return false;
  306.         }
  307.     } catch (e) {
  308.         console.log("❌ 路径滑动失败: " + e);
  309.         return false;
  310.     }
  311. }

  312. /**
  313. * 安卓自动化滑动示例
  314. * 使用auto.swip方法
  315. */
  316. function autoSwipeExample() {
  317.     try {
  318.         if (typeof auto !== 'undefined' && typeof auto.swip === 'function') {
  319.             console.log("执行安卓自动化滑动示例");
  320.             auto.swip(50, 100, 500, 100, 500, 0);
  321.             console.log("安卓自动化滑动执行成功");
  322.             return true;
  323.         } else {
  324.             console.log("❌ 安卓自动化模块或swip方法不可用");
  325.             return false;
  326.         }
  327.     } catch (e) {
  328.         console.log("❌ 安卓自动化滑动失败: " + e);
  329.         return false;
  330.     }
  331. }

  332. /**
  333. * 节点滑动示例
  334. * 使用node对象的swipNext和swipPervious方法
  335. */
  336. function nodeSwipeExample() {
  337.     try {
  338.         console.log("执行节点滑动示例");
  339.         
  340.         // 检查node构造函数是否可用
  341.         if (typeof node !== 'undefined') {
  342.             try {
  343.                 // 创建node对象
  344.                 var node = new node();
  345.                
  346.                 // 滑动下一页
  347.                 if (node && typeof node.swipNext === 'function') {
  348.                     node.swipNext();
  349.                     console.log("节点滑动下一页执行成功");
  350.                 } else {
  351.                     console.log("❌ node对象或swipNext方法不可用");
  352.                 }
  353.                
  354.                 // 滑动上一页
  355.                 if (node && typeof node.swipPervious === 'function') {
  356.                     node.swipPervious();
  357.                     console.log("节点滑动上一页执行成功");
  358.                 } else {
  359.                     console.log("❌ node对象或swipPervious方法不可用");
  360.                 }
  361.             } catch (nodeError) {
  362.                 console.log("❌ 创建node对象失败: " + nodeError);
  363.                 // 跳过节点滑动,继续执行其他滑动方法
  364.             }
  365.         } else {
  366.             console.log("❌ node构造函数不可用");
  367.         }
  368.         
  369.         return true;
  370.     } catch (e) {
  371.         console.log("❌ 节点滑动失败: " + e);
  372.         return false;
  373.     }
  374. }

  375. /**
  376. * 安卓自动化 手势滑动
  377. * @param {Array} points - 坐标点数组 [[x1,y1],[x2,y2],...]
  378. * @param {number} duration - 滑动持续时间(毫秒)
  379. */
  380. function autoDispatchGesture(points, duration) {
  381.     try {
  382.         if (typeof auto !== 'undefined' && typeof auto.dispatchGesture === 'function') {
  383.             console.log("执行安卓自动化手势滑动: " + points.length + "个点 持续" + duration + "ms");
  384.             auto.dispatchGesture(points, duration);
  385.             return true;
  386.         } else {
  387.             console.log("❌ 安卓自动化模块或dispatchGesture方法不可用");
  388.             return false;
  389.         }
  390.     } catch (e) {
  391.         console.log("❌ 安卓自动化手势滑动失败: " + e);
  392.         return false;
  393.     }
  394. }

  395. /**
  396. * 安卓自动化 滑动
  397. * @param {number} startX - 起始X坐标
  398. * @param {number} startY - 起始Y坐标
  399. * @param {number} endX - 结束X坐标
  400. * @param {number} endY - 结束Y坐标
  401. * @param {number} duration - 滑动持续时间(毫秒)
  402. */
  403. function autoSwipe(startX, startY, endX, endY, duration) {
  404.     try {
  405.         if (typeof auto !== 'undefined' && typeof auto.swip === 'function') {
  406.             console.log("执行安卓自动化滑动: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ") 持续" + duration + "ms");
  407.             auto.swip(startX, startY, endX, endY, duration);
  408.             return true;
  409.         } else {
  410.             console.log("❌ 安卓自动化模块或swip方法不可用");
  411.             return false;
  412.         }
  413.     } catch (e) {
  414.         console.log("❌ 安卓自动化滑动失败: " + e);
  415.         return false;
  416.     }
  417. }

  418. /**
  419. * 安卓自动化 百分比坐标滑动
  420. * @param {number} startX - 起始X百分比
  421. * @param {number} startY - 起始Y百分比
  422. * @param {number} endX - 结束X百分比
  423. * @param {number} endY - 结束Y百分比
  424. * @param {number} duration - 滑动持续时间(毫秒)
  425. */
  426. function autoSwipePercent(startX, startY, endX, endY, duration) {
  427.     try {
  428.         if (typeof auto !== 'undefined' && typeof auto.swipPercent === 'function') {
  429.             console.log("执行安卓自动化百分比坐标滑动: " + startX + "%x" + startY + "% -> " + endX + "%x" + endY + "% 持续" + duration + "ms");
  430.             auto.swipPercent(startX, startY, endX, endY, duration);
  431.             return true;
  432.         } else {
  433.             console.log("❌ 安卓自动化模块或swipPercent方法不可用");
  434.             return false;
  435.         }
  436.     } catch (e) {
  437.         console.log("❌ 安卓自动化百分比坐标滑动失败: " + e);
  438.         return false;
  439.     }
  440. }

  441. /**
  442. * 增强版滑动方法
  443. * 使用多种滑动方式组合,提高滑动成功率
  444. * @param {number} startX - 起始X百分比
  445. * @param {number} startY - 起始Y百分比
  446. * @param {number} endX - 结束X百分比
  447. * @param {number} endY - 结束Y百分比
  448. * @param {number} duration - 滑动持续时间(毫秒)
  449. */
  450. function enhancedSwipe(startX, startY, endX, endY, duration) {
  451.     try {
  452.         console.log("执行增强版滑动: " + startX + "%x" + startY + "% -> " + endX + "%x" + endY + "% 持续" + duration + "ms");
  453.         
  454.         var screenSize = getScreenSize();
  455.         var sx = Math.round(screenSize.width * startX);
  456.         var sy = Math.round(screenSize.height * startY);
  457.         var ex = Math.round(screenSize.width * endX);
  458.         var ey = Math.round(screenSize.height * endY);
  459.         
  460.         // 尝试多种滑动方法
  461.         var methods = [
  462.             function() {
  463.                 if (typeof auto !== 'undefined' && typeof auto.swip === 'function') {
  464.                     console.log("增强版滑动 - 使用auto.swip");
  465.                     auto.swip(sx, sy, ex, ey, duration, 0);
  466.                     return true;
  467.                 }
  468.                 return false;
  469.             },
  470.             function() {
  471.                 if (typeof auto !== 'undefined' && typeof auto.swipPercent === 'function') {
  472.                     console.log("增强版滑动 - 使用auto.swipPercent");
  473.                     auto.swipPercent(startX, startY, endX, endY, duration);
  474.                     return true;
  475.                 }
  476.                 return false;
  477.             },
  478.             function() {
  479.                 if (typeof auto !== 'undefined' && typeof auto.dispatchGesture === 'function') {
  480.                     console.log("增强版滑动 - 使用auto.dispatchGesture");
  481.                     var points = [[sx, sy], [ex, ey]];
  482.                     auto.dispatchGesture(points, duration);
  483.                     return true;
  484.                 }
  485.                 return false;
  486.             }
  487.         ];
  488.         
  489.         // 尝试每种方法,直到成功
  490.         for (var i = 0; i < methods.length; i++) {
  491.             try {
  492.                 if (methods[i]()) {
  493.                     console.log("增强版滑动执行成功");
  494.                     return true;
  495.                 }
  496.             } catch (e) {
  497.                 console.log("增强版滑动方法" + i + "失败: " + e);
  498.             }
  499.         }
  500.         
  501.         console.log("❌ 所有滑动方法都失败");
  502.         return false;
  503.     } catch (e) {
  504.         console.log("❌ 增强版滑动失败: " + e);
  505.         return false;
  506.     }
  507. }

  508. /**
  509. * 安卓自动化 滑动示例集合
  510. */
  511. function androidSwipeExamples() {
  512.     console.log("\n=== 安卓自动化滑动示例集合 ===");
  513.    
  514.     // 执行路径滑动示例
  515.     pathSwipeExample();
  516.     sleep.millisecond(1000);
  517.    
  518.     // 执行安卓自动化滑动示例
  519.     autoSwipeExample();
  520.     sleep.millisecond(1000);
  521.    
  522.     // 执行节点滑动示例
  523.     nodeSwipeExample();
  524.     sleep.millisecond(1000);
  525.    
  526.     // 执行百分比坐标滑动2.0示例
  527.     autoSwipePercentV2(0.5, 0.8, 0.5, 0.2, 1000, 2000);
  528.     sleep.millisecond(1000);
  529.    
  530.     // 执行增强版滑动示例
  531.     console.log("执行增强版滑动示例");
  532.     enhancedSwipe(0.2, 0.5, 0.8, 0.5, 500); // 向右滑动
  533.     sleep.millisecond(1000);
  534.     enhancedSwipe(0.5, 0.8, 0.5, 0.2, 800); // 向上滑动
  535.     sleep.millisecond(1000);
  536.    
  537.     console.log("=== 安卓自动化滑动示例集合完成 ===");
  538. }

  539. // ==================== 4. 常用滑动操作 ====================

  540. /**
  541. * 常用滑动操作集合
  542. */
  543. function commonSwipeOperations() {
  544.     console.log("\n=== 常用滑动操作示例 ===");
  545.    
  546.     // 1. 向右滑动
  547.     console.log("1. 向右滑动");
  548.     enhancedSwipe(0.2, 0.5, 0.8, 0.5, 500);
  549.     sleep.millisecond(1000);
  550.    
  551.     // 2. 向左滑动
  552.     console.log("2. 向左滑动");
  553.     enhancedSwipe(0.8, 0.5, 0.2, 0.5, 500);
  554.     sleep.millisecond(1000);
  555.    
  556.     // 3. 向上滑动
  557.     console.log("3. 向上滑动");
  558.     enhancedSwipe(0.5, 0.8, 0.5, 0.2, 800);
  559.     sleep.millisecond(1000);
  560.    
  561.     // 4. 向下滑动
  562.     console.log("4. 向下滑动");
  563.     enhancedSwipe(0.5, 0.2, 0.5, 0.8, 800);
  564.     sleep.millisecond(1000);
  565.    
  566.     // 5. 从底部向上滑动(打开通知栏)
  567.     console.log("5. 从底部向上滑动");
  568.     enhancedSwipe(0.5, 0.9, 0.5, 0.1, 1000);
  569.     sleep.millisecond(1000);
  570.    
  571.     // 6. 从顶部向下滑动(关闭通知栏)
  572.     console.log("6. 从顶部向下滑动");
  573.     enhancedSwipe(0.5, 0.1, 0.5, 0.3, 500);
  574.     sleep.millisecond(1000);
  575.    
  576.     console.log("=== 常用滑动操作完成 ===");
  577. }

  578. /**
  579. * 使用指定坐标滑动
  580. * 初始坐标:0.4774,0.7945
  581. * 终点坐标:0.4568,0.1784
  582. */
  583. function customCoordinateSwipe() {
  584.     console.log("\n=== 使用指定坐标滑动 ===");
  585.    
  586.     var startX = 0.4774;
  587.     var startY = 0.7945;
  588.     var endX = 0.4568;
  589.     var endY = 0.1784;
  590.    
  591.     console.log("初始坐标: " + startX + ", " + startY);
  592.     console.log("终点坐标: " + endX + ", " + endY);
  593.    
  594.     // 使用增强版滑动方法
  595.     enhancedSwipe(startX, startY, endX, endY, 800);
  596.     sleep.millisecond(1000);
  597.    
  598.     console.log("=== 指定坐标滑动完成 ===");
  599. }

  600. // ==================== 5. 找图功能示例 ====================

  601. /**
  602. * 找图功能示例(使用指定的CV文件)
  603. */
  604. function findImageExample() {
  605.     console.log("\n=== 找图功能示例 ===");
  606.    
  607.     try {
  608.         // 使用用户指定的CV文件
  609.         var cvFile = '图色345140.cv';
  610.         console.log("开始使用CV文件找图: " + cvFile);
  611.         
  612.         // 检查opencv是否可用
  613.         if (typeof opencv !== 'undefined' && typeof opencv.findImagesEx === 'function') {
  614.             // 执行找图操作
  615.             var detects = opencv.findImagesEx(cvFile);
  616.             
  617.             if (detects !== null) {
  618.                 console.log("找到目标数组: " + detects);
  619.                
  620.                 // 点击第一个找到的目标
  621.                 if (detects.length > 0) {
  622.                     console.log("点击第一个找到的目标");
  623.                     detects[0].click();
  624.                     return true;
  625.                 } else {
  626.                     console.log("目标数组为空");
  627.                     return false;
  628.                 }
  629.             } else {
  630.                 console.log("未找到目标");
  631.                 return false;
  632.             }
  633.         } else {
  634.             console.log("❌ opencv模块不可用");
  635.             return false;
  636.         }
  637.     } catch (e) {
  638.         console.log("❌ 找图失败: " + e);
  639.         return false;
  640.     }
  641. }

  642. // ==================== 6. 组合操作示例 ====================

  643. /**
  644. * 找图后滑动示例
  645. */
  646. function findImageAndSwipeExample() {
  647.     console.log("\n=== 找图后滑动示例 ===");
  648.    
  649.     try {
  650.         var cvFile = '图色345140.cv';
  651.         console.log("开始找图: " + cvFile);
  652.         
  653.         if (typeof opencv !== 'undefined' && typeof opencv.findImagesEx === 'function') {
  654.             var detects = opencv.findImagesEx(cvFile);
  655.             
  656.             if (detects !== null && detects.length > 0) {
  657.                 console.log("找到目标,执行滑动操作");
  658.                
  659.                 // 点击目标
  660.                 detects[0].click();
  661.                 sleep.millisecond(500);
  662.                
  663.                 // 执行向上滑动
  664.                 swipeWithPercentCoordinates(0.5, 0.7, 0.5, 0.3, 500);
  665.                 sleep.millisecond(1000);
  666.                
  667.                 // 执行向右滑动
  668.                 swipeWithPercentCoordinates(0.3, 0.5, 0.7, 0.5, 300);
  669.                
  670.                 return true;
  671.             } else {
  672.                 console.log("未找到目标,执行默认滑动操作");
  673.                
  674.                 // 执行默认滑动操作
  675.                 commonSwipeOperations();
  676.                 return false;
  677.             }
  678.         } else {
  679.             console.log("❌ opencv模块不可用,执行默认滑动操作");
  680.             commonSwipeOperations();
  681.             return false;
  682.         }
  683.     } catch (e) {
  684.         console.log("❌ 找图后滑动失败: " + e);
  685.         return false;
  686.     }
  687. }

  688. // ==================== 7. 主函数 ====================

  689. /**
  690. * 主函数
  691. */
  692. function main() {
  693.     console.log("====================================");
  694.     console.log("         滑动方法集合示例");
  695.     console.log("====================================");
  696.    
  697.     // 1. 执行找图功能
  698.     findImageExample();
  699.    
  700.     // 2. 执行常用滑动操作
  701.     commonSwipeOperations();
  702.    
  703.     // 3. 执行指定坐标滑动
  704.     customCoordinateSwipe();
  705.    
  706.     // 4. 执行安卓自动化滑动示例集合
  707.     androidSwipeExamples();
  708.    
  709.     // 5. 执行找图后滑动示例
  710.     findImageAndSwipeExample();
  711.    
  712.     console.log("====================================");
  713.     console.log("         示例执行完成");
  714.     console.log("====================================");
  715. }

  716. // 执行主函数
  717. main();
复制代码







欢迎光临 B2B网络软件 (http://bbs.niubt.cn/) Powered by Discuz! X3.2