YYPOST群发软件 发表于 2026-2-4 08:58:47

AIWROK软件滑动方法集合示例

AIWROK软件滑动方法集合示例




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

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

/**
* 基础滑动方法
* @param {number} startX - 起始X坐标
* @param {number} startY - 起始Y坐标
* @param {number} endX - 结束X坐标
* @param {number} endY - 结束Y坐标
* @param {number} duration - 滑动持续时间(毫秒)
*/
function basicSwipe(startX, startY, endX, endY, duration) {
    try {
      console.log("执行基础滑动: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ") 持续" + duration + "ms");
      
      // 优先使用auto.swip(根据日志显示这个方法可用)
      if (typeof auto !== 'undefined' && typeof auto.swip === 'function') {
            console.log("使用auto.swip方法");
            auto.swip(startX, startY, endX, endY, duration, 0);
            return true;
      }
      // 尝试使用swipe方法
      else if (typeof swipe !== 'undefined') {
            console.log("使用swipe方法");
            swipe(startX, startY, endX, endY, duration);
            return true;
      }
      // 尝试使用touch.swipe方法
      else if (typeof touch !== 'undefined' && typeof touch.swipe === 'function') {
            console.log("使用touch.swipe方法");
            touch.swipe(startX, startY, endX, endY, duration);
            return true;
      }
      // 尝试使用HID滑动方法
      else if (typeof hid !== 'undefined' && typeof hid.swip === 'function') {
            console.log("使用hid.swip方法");
            hid.swip(startX, startY, endX, endY, 10, duration, 0);
            return true;
      }
      // 尝试使用手势滑动
      else if (typeof auto !== 'undefined' && typeof auto.dispatchGesture === 'function') {
            console.log("使用auto.dispatchGesture方法");
            var points = [, ];
            auto.dispatchGesture(points, duration);
            return true;
      }
      else {
            console.log("❌ 未找到可用的滑动方法");
            return false;
      }
    } catch (e) {
      console.log("❌ 基础滑动失败: " + e);
      return false;
    }
}

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

/**
* 获取屏幕尺寸
* @returns {Object} 包含width和height的对象
*/
function getScreenSize() {
    var width = 1080;
    var height = 1920;
   
    try {
      if (typeof screen !== 'undefined') {
            if (typeof screen.getScreenWidth === 'function') {
                width = screen.getScreenWidth();
            }
            if (typeof screen.getScreenHeight === 'function') {
                height = screen.getScreenHeight();
            }
      } else if (typeof device !== 'undefined') {
            if (typeof device.width === 'number') {
                width = device.width;
            }
            if (typeof device.height === 'number') {
                height = device.height;
            }
      }
    } catch (e) {
      console.log("❌ 获取屏幕尺寸失败: " + e);
    }
   
    return { width: width, height: height };
}

/**
* 百分比坐标滑动
* @param {number} startXPercent - 起始X百分比 (0-1)
* @param {number} startYPercent - 起始Y百分比 (0-1)
* @param {number} endXPercent - 结束X百分比 (0-1)
* @param {number} endYPercent - 结束Y百分比 (0-1)
* @param {number} duration - 滑动持续时间(毫秒)
*/
function swipeWithPercentCoordinates(startXPercent, startYPercent, endXPercent, endYPercent, duration) {
    try {
      var screenSize = getScreenSize();
      var startX = Math.round(screenSize.width * startXPercent);
      var startY = Math.round(screenSize.height * startYPercent);
      var endX = Math.round(screenSize.width * endXPercent);
      var endY = Math.round(screenSize.height * endYPercent);
      
      console.log("执行百分比坐标滑动: " +
               (startXPercent * 100).toFixed(0) + "%x" + (startYPercent * 100).toFixed(0) + "% -> " +
               (endXPercent * 100).toFixed(0) + "%x" + (endYPercent * 100).toFixed(0) + "% 持续" + duration + "ms");
      
      return basicSwipe(startX, startY, endX, endY, duration);
    } catch (e) {
      console.log("❌ 百分比坐标滑动失败: " + e);
      return false;
    }
}

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

/**
* HID滑动方法
* @param {number} startX - 起始X坐标
* @param {number} startY - 起始Y坐标
* @param {number} endX - 结束X坐标
* @param {number} endY - 结束Y坐标
* @param {number} steps - 滑动步数
* @param {number} duration - 滑动持续时间(毫秒)
* @param {number} direction - 滑动方向
*/
function hidSwipe(startX, startY, endX, endY, steps, duration, direction) {
    try {
      if (typeof hid !== 'undefined' && typeof hid.swip === 'function') {
            console.log("执行HID滑动: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ") 步数:" + steps + " 持续" + duration + "ms");
            hid.swip(startX, startY, endX, endY, steps, duration, direction);
            return true;
      } else {
            console.log("❌ HID模块不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ HID滑动失败: " + e);
      return false;
    }
}

/**
* HID AI智能滑动
* @param {number} startX - 起始X坐标
* @param {number} startY - 起始Y坐标
* @param {number} endX - 结束X坐标
* @param {number} endY - 结束Y坐标
*/
function hidSwipeAI(startX, startY, endX, endY) {
    try {
      if (typeof hid !== 'undefined' && typeof hid.swipAI === 'function') {
            console.log("执行HID AI智能滑动: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ")");
            hid.swipAI(startX, startY, endX, endY);
            return true;
      } else {
            console.log("❌ HID模块或swipAI方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ HID AI滑动失败: " + e);
      return false;
    }
}

/**
* HID 鼠标滑动
* @param {number} startX - 起始X坐标
* @param {number} startY - 起始Y坐标
* @param {number} endX - 结束X坐标
* @param {number} endY - 结束Y坐标
* @param {number} duration - 滑动持续时间(毫秒)
*/
function hidMouseSwipe(startX, startY, endX, endY, duration) {
    try {
      if (typeof hid !== 'undefined' && typeof hid.mouseSwip === 'function') {
            console.log("执行HID鼠标滑动: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ") 持续" + duration + "ms");
            hid.mouseSwip(startX, startY, endX, endY, duration);
            return true;
      } else {
            console.log("❌ HID模块或mouseSwip方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ HID鼠标滑动失败: " + e);
      return false;
    }
}

/**
* HID 滑动增强版
* @param {number} startX - 起始X坐标
* @param {number} startY - 起始Y坐标
* @param {number} endX - 结束X坐标
* @param {number} endY - 结束Y坐标
* @param {number} duration - 滑动持续时间(毫秒)
*/
function hidSwipeEx(startX, startY, endX, endY, duration) {
    try {
      if (typeof hid !== 'undefined' && typeof hid.swipEx === 'function') {
            console.log("执行HID滑动增强版: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ") 持续" + duration + "ms");
            hid.swipEx(startX, startY, endX, endY, duration);
            return true;
      } else {
            console.log("❌ HID模块或swipEx方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ HID滑动增强版失败: " + e);
      return false;
    }
}

/**
* HID 快速滑动
* @param {number} startX - 起始X坐标
* @param {number} startY - 起始Y坐标
* @param {number} endX - 结束X坐标
* @param {number} endY - 结束Y坐标
*/
function hidSwipeM(startX, startY, endX, endY) {
    try {
      if (typeof hid !== 'undefined' && typeof hid.swipM === 'function') {
            console.log("执行HID快速滑动: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ")");
            hid.swipM(startX, startY, endX, endY);
            return true;
      } else {
            console.log("❌ HID模块或swipM方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ HID快速滑动失败: " + e);
      return false;
    }
}

/**
* HID 多段滑动
* @param {Array} points - 坐标点数组 [,,...]
* @param {number} duration - 滑动持续时间(毫秒)
*/
function hidSwipeMultiple(points, duration) {
    try {
      if (typeof hid !== 'undefined' && typeof hid.swipMultiple === 'function') {
            console.log("执行HID多段滑动: " + points.length + "个点 持续" + duration + "ms");
            hid.swipMultiple(points, duration);
            return true;
      } else {
            console.log("❌ HID模块或swipMultiple方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ HID多段滑动失败: " + e);
      return false;
    }
}

/**
* 安卓自动化 百分比坐标滑动2.0
* @param {number} startX - 起始X百分比
* @param {number} startY - 起始Y百分比
* @param {number} endX - 结束X百分比
* @param {number} endY - 结束Y百分比
* @param {number} duration - 滑动持续时间(毫秒)
* @param {number} steps - 滑动步数
*/
function autoSwipePercentV2(startX, startY, endX, endY, duration, steps) {
    try {
      if (typeof auto !== 'undefined' && typeof auto.swipPercent_v2 === 'function') {
            console.log("执行安卓自动化百分比坐标滑动2.0: " + startX + "%x" + startY + "% -> " + endX + "%x" + endY + "% 持续" + duration + "ms 步数:" + steps);
            auto.swipPercent_v2(startX, startY, endX, endY, duration, steps);
            return true;
      } else {
            console.log("❌ 安卓自动化模块或swipPercent_v2方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ 安卓自动化百分比坐标滑动2.0失败: " + e);
      return false;
    }
}

/**
* 路径滑动示例
* 使用path对象创建滑动轨迹
*/
function pathSwipeExample() {
    try {
      if (typeof path !== 'undefined') {
            console.log("执行路径滑动示例");
            
            // 定义滑动轨迹
            var p1 = new path();
            // 设置滑动时间
            p1.setDurTime(600);
            // 添加起点
            p1.addPoint(100, 100);
            // 再添加一个点
            p1.addPoint(500, 100);
            // 还可以继续添加点 形成一个轨迹
            p1.addPoint(800, 200);
            
            // 执行手势滑动
            if (typeof auto !== 'undefined' && typeof auto.dispatchGesture === 'function') {
                auto.dispatchGesture();
                console.log("路径滑动执行成功");
                return true;
            } else {
                console.log("❌ 安卓自动化模块或dispatchGesture方法不可用");
                return false;
            }
      } else {
            console.log("❌ path模块不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ 路径滑动失败: " + e);
      return false;
    }
}

/**
* 安卓自动化滑动示例
* 使用auto.swip方法
*/
function autoSwipeExample() {
    try {
      if (typeof auto !== 'undefined' && typeof auto.swip === 'function') {
            console.log("执行安卓自动化滑动示例");
            auto.swip(50, 100, 500, 100, 500, 0);
            console.log("安卓自动化滑动执行成功");
            return true;
      } else {
            console.log("❌ 安卓自动化模块或swip方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ 安卓自动化滑动失败: " + e);
      return false;
    }
}

/**
* 节点滑动示例
* 使用node对象的swipNext和swipPervious方法
*/
function nodeSwipeExample() {
    try {
      console.log("执行节点滑动示例");
      
      // 检查node构造函数是否可用
      if (typeof node !== 'undefined') {
            try {
                // 创建node对象
                var node = new node();
               
                // 滑动下一页
                if (node && typeof node.swipNext === 'function') {
                  node.swipNext();
                  console.log("节点滑动下一页执行成功");
                } else {
                  console.log("❌ node对象或swipNext方法不可用");
                }
               
                // 滑动上一页
                if (node && typeof node.swipPervious === 'function') {
                  node.swipPervious();
                  console.log("节点滑动上一页执行成功");
                } else {
                  console.log("❌ node对象或swipPervious方法不可用");
                }
            } catch (nodeError) {
                console.log("❌ 创建node对象失败: " + nodeError);
                // 跳过节点滑动,继续执行其他滑动方法
            }
      } else {
            console.log("❌ node构造函数不可用");
      }
      
      return true;
    } catch (e) {
      console.log("❌ 节点滑动失败: " + e);
      return false;
    }
}

/**
* 安卓自动化 手势滑动
* @param {Array} points - 坐标点数组 [,,...]
* @param {number} duration - 滑动持续时间(毫秒)
*/
function autoDispatchGesture(points, duration) {
    try {
      if (typeof auto !== 'undefined' && typeof auto.dispatchGesture === 'function') {
            console.log("执行安卓自动化手势滑动: " + points.length + "个点 持续" + duration + "ms");
            auto.dispatchGesture(points, duration);
            return true;
      } else {
            console.log("❌ 安卓自动化模块或dispatchGesture方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ 安卓自动化手势滑动失败: " + e);
      return false;
    }
}

/**
* 安卓自动化 滑动
* @param {number} startX - 起始X坐标
* @param {number} startY - 起始Y坐标
* @param {number} endX - 结束X坐标
* @param {number} endY - 结束Y坐标
* @param {number} duration - 滑动持续时间(毫秒)
*/
function autoSwipe(startX, startY, endX, endY, duration) {
    try {
      if (typeof auto !== 'undefined' && typeof auto.swip === 'function') {
            console.log("执行安卓自动化滑动: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ") 持续" + duration + "ms");
            auto.swip(startX, startY, endX, endY, duration);
            return true;
      } else {
            console.log("❌ 安卓自动化模块或swip方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ 安卓自动化滑动失败: " + e);
      return false;
    }
}

/**
* 安卓自动化 百分比坐标滑动
* @param {number} startX - 起始X百分比
* @param {number} startY - 起始Y百分比
* @param {number} endX - 结束X百分比
* @param {number} endY - 结束Y百分比
* @param {number} duration - 滑动持续时间(毫秒)
*/
function autoSwipePercent(startX, startY, endX, endY, duration) {
    try {
      if (typeof auto !== 'undefined' && typeof auto.swipPercent === 'function') {
            console.log("执行安卓自动化百分比坐标滑动: " + startX + "%x" + startY + "% -> " + endX + "%x" + endY + "% 持续" + duration + "ms");
            auto.swipPercent(startX, startY, endX, endY, duration);
            return true;
      } else {
            console.log("❌ 安卓自动化模块或swipPercent方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ 安卓自动化百分比坐标滑动失败: " + e);
      return false;
    }
}

/**
* 增强版滑动方法
* 使用多种滑动方式组合,提高滑动成功率
* @param {number} startX - 起始X百分比
* @param {number} startY - 起始Y百分比
* @param {number} endX - 结束X百分比
* @param {number} endY - 结束Y百分比
* @param {number} duration - 滑动持续时间(毫秒)
*/
function enhancedSwipe(startX, startY, endX, endY, duration) {
    try {
      console.log("执行增强版滑动: " + startX + "%x" + startY + "% -> " + endX + "%x" + endY + "% 持续" + duration + "ms");
      
      var screenSize = getScreenSize();
      var sx = Math.round(screenSize.width * startX);
      var sy = Math.round(screenSize.height * startY);
      var ex = Math.round(screenSize.width * endX);
      var ey = Math.round(screenSize.height * endY);
      
      // 尝试多种滑动方法
      var methods = [
            function() {
                if (typeof auto !== 'undefined' && typeof auto.swip === 'function') {
                  console.log("增强版滑动 - 使用auto.swip");
                  auto.swip(sx, sy, ex, ey, duration, 0);
                  return true;
                }
                return false;
            },
            function() {
                if (typeof auto !== 'undefined' && typeof auto.swipPercent === 'function') {
                  console.log("增强版滑动 - 使用auto.swipPercent");
                  auto.swipPercent(startX, startY, endX, endY, duration);
                  return true;
                }
                return false;
            },
            function() {
                if (typeof auto !== 'undefined' && typeof auto.dispatchGesture === 'function') {
                  console.log("增强版滑动 - 使用auto.dispatchGesture");
                  var points = [, ];
                  auto.dispatchGesture(points, duration);
                  return true;
                }
                return false;
            }
      ];
      
      // 尝试每种方法,直到成功
      for (var i = 0; i < methods.length; i++) {
            try {
                if (methods()) {
                  console.log("增强版滑动执行成功");
                  return true;
                }
            } catch (e) {
                console.log("增强版滑动方法" + i + "失败: " + e);
            }
      }
      
      console.log("❌ 所有滑动方法都失败");
      return false;
    } catch (e) {
      console.log("❌ 增强版滑动失败: " + e);
      return false;
    }
}

/**
* 安卓自动化 滑动示例集合
*/
function androidSwipeExamples() {
    console.log("\n=== 安卓自动化滑动示例集合 ===");
   
    // 执行路径滑动示例
    pathSwipeExample();
    sleep.millisecond(1000);
   
    // 执行安卓自动化滑动示例
    autoSwipeExample();
    sleep.millisecond(1000);
   
    // 执行节点滑动示例
    nodeSwipeExample();
    sleep.millisecond(1000);
   
    // 执行百分比坐标滑动2.0示例
    autoSwipePercentV2(0.5, 0.8, 0.5, 0.2, 1000, 2000);
    sleep.millisecond(1000);
   
    // 执行增强版滑动示例
    console.log("执行增强版滑动示例");
    enhancedSwipe(0.2, 0.5, 0.8, 0.5, 500); // 向右滑动
    sleep.millisecond(1000);
    enhancedSwipe(0.5, 0.8, 0.5, 0.2, 800); // 向上滑动
    sleep.millisecond(1000);
   
    console.log("=== 安卓自动化滑动示例集合完成 ===");
}

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

/**
* 常用滑动操作集合
*/
function commonSwipeOperations() {
    console.log("\n=== 常用滑动操作示例 ===");
   
    // 1. 向右滑动
    console.log("1. 向右滑动");
    enhancedSwipe(0.2, 0.5, 0.8, 0.5, 500);
    sleep.millisecond(1000);
   
    // 2. 向左滑动
    console.log("2. 向左滑动");
    enhancedSwipe(0.8, 0.5, 0.2, 0.5, 500);
    sleep.millisecond(1000);
   
    // 3. 向上滑动
    console.log("3. 向上滑动");
    enhancedSwipe(0.5, 0.8, 0.5, 0.2, 800);
    sleep.millisecond(1000);
   
    // 4. 向下滑动
    console.log("4. 向下滑动");
    enhancedSwipe(0.5, 0.2, 0.5, 0.8, 800);
    sleep.millisecond(1000);
   
    // 5. 从底部向上滑动(打开通知栏)
    console.log("5. 从底部向上滑动");
    enhancedSwipe(0.5, 0.9, 0.5, 0.1, 1000);
    sleep.millisecond(1000);
   
    // 6. 从顶部向下滑动(关闭通知栏)
    console.log("6. 从顶部向下滑动");
    enhancedSwipe(0.5, 0.1, 0.5, 0.3, 500);
    sleep.millisecond(1000);
   
    console.log("=== 常用滑动操作完成 ===");
}

/**
* 使用指定坐标滑动
* 初始坐标:0.4774,0.7945
* 终点坐标:0.4568,0.1784
*/
function customCoordinateSwipe() {
    console.log("\n=== 使用指定坐标滑动 ===");
   
    var startX = 0.4774;
    var startY = 0.7945;
    var endX = 0.4568;
    var endY = 0.1784;
   
    console.log("初始坐标: " + startX + ", " + startY);
    console.log("终点坐标: " + endX + ", " + endY);
   
    // 使用增强版滑动方法
    enhancedSwipe(startX, startY, endX, endY, 800);
    sleep.millisecond(1000);
   
    console.log("=== 指定坐标滑动完成 ===");
}

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

/**
* 找图功能示例(使用指定的CV文件)
*/
function findImageExample() {
    console.log("\n=== 找图功能示例 ===");
   
    try {
      // 使用用户指定的CV文件
      var cvFile = '图色345140.cv';
      console.log("开始使用CV文件找图: " + cvFile);
      
      // 检查opencv是否可用
      if (typeof opencv !== 'undefined' && typeof opencv.findImagesEx === 'function') {
            // 执行找图操作
            var detects = opencv.findImagesEx(cvFile);
            
            if (detects !== null) {
                console.log("找到目标数组: " + detects);
               
                // 点击第一个找到的目标
                if (detects.length > 0) {
                  console.log("点击第一个找到的目标");
                  detects.click();
                  return true;
                } else {
                  console.log("目标数组为空");
                  return false;
                }
            } else {
                console.log("未找到目标");
                return false;
            }
      } else {
            console.log("❌ opencv模块不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ 找图失败: " + e);
      return false;
    }
}

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

/**
* 找图后滑动示例
*/
function findImageAndSwipeExample() {
    console.log("\n=== 找图后滑动示例 ===");
   
    try {
      var cvFile = '图色345140.cv';
      console.log("开始找图: " + cvFile);
      
      if (typeof opencv !== 'undefined' && typeof opencv.findImagesEx === 'function') {
            var detects = opencv.findImagesEx(cvFile);
            
            if (detects !== null && detects.length > 0) {
                console.log("找到目标,执行滑动操作");
               
                // 点击目标
                detects.click();
                sleep.millisecond(500);
               
                // 执行向上滑动
                swipeWithPercentCoordinates(0.5, 0.7, 0.5, 0.3, 500);
                sleep.millisecond(1000);
               
                // 执行向右滑动
                swipeWithPercentCoordinates(0.3, 0.5, 0.7, 0.5, 300);
               
                return true;
            } else {
                console.log("未找到目标,执行默认滑动操作");
               
                // 执行默认滑动操作
                commonSwipeOperations();
                return false;
            }
      } else {
            console.log("❌ opencv模块不可用,执行默认滑动操作");
            commonSwipeOperations();
            return false;
      }
    } catch (e) {
      console.log("❌ 找图后滑动失败: " + e);
      return false;
    }
}

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

/**
* 主函数
*/
function main() {
    console.log("====================================");
    console.log("         滑动方法集合示例");
    console.log("====================================");
   
    // 1. 执行找图功能
    findImageExample();
   
    // 2. 执行常用滑动操作
    commonSwipeOperations();
   
    // 3. 执行指定坐标滑动
    customCoordinateSwipe();
   
    // 4. 执行安卓自动化滑动示例集合
    androidSwipeExamples();
   
    // 5. 执行找图后滑动示例
    findImageAndSwipeExample();
   
    console.log("====================================");
    console.log("         示例执行完成");
    console.log("====================================");
}

// 执行主函数
main();


页: [1]
查看完整版本: AIWROK软件滑动方法集合示例