YYPOST群发软件 发表于 2026-5-22 06:44:23

AIWROK软件键鼠HID滑动所有方法功能演示

AIWROK软件键鼠HID滑动所有方法功能演示






/**
* AIWROK HID 滑动所有方法功能演示
* 集成展示所有可用的HID滑动方法及其使用方式
*
* @author AIWROK开发团队
* @version 1.0.0
* @copyright Copyright (c) 2026 AIWROK. All rights reserved.
* @qq_group AIWROK官方群: 711841924,苹果群,528816639
*/

// ==================== 基础配置 ====================
var DURATION = 1000; // 滑动持续时间(毫秒)

// ==================== 延时配置(针对抖音等慢加载应用)====================
// 提示:如果您的应用加载较慢,可以增加以下延时值
var DELAY_CONFIG = {
    appStartDelay: 3000,      // 应用启动后等待时间(毫秒)- 抖音建议 3000-5000ms
    pageLoadDelay: 2000,      // 页面加载等待时间(毫秒)- 抖音建议 2000-3000ms
    swipeInterval: 1500,      // 滑动间隔时间(毫秒)- 抖音建议 1500-2500ms
    contentLoadDelay: 2500,   // 内容加载等待时间(毫秒)- 抖音视频加载建议 2500-4000ms
    operationDelay: 1000      // 操作间基础延时(毫秒)
};

// ==================== 获取屏幕尺寸 ====================

/**
* 智能等待函数
* @param {string} description - 等待描述
* @param {number} delay - 等待时间(毫秒),默认使用配置值
*/
function smartWait(description, delay) {
    var waitTime = delay || DELAY_CONFIG.operationDelay;
    console.log("⏱️" + description + " (等待" + waitTime + "ms)");
    sleep.millisecond(waitTime);
}

/**
* 等待页面加载完成
* @param {string} description - 描述信息
*/
function waitForPageLoad(description) {
    console.log("📄 " + description);
    smartWait("等待页面加载", DELAY_CONFIG.pageLoadDelay);
}

/**
* 等待内容加载完成
* @param {string} description - 描述信息
*/
function waitForContentLoad(description) {
    console.log("🎬 " + description);
    smartWait("等待内容加载", DELAY_CONFIG.contentLoadDelay);
}

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

// 获取实际屏幕尺寸
var SCREEN_SIZE = getScreenSize();
var START_X = Math.round(SCREEN_SIZE.width * 0.2);
var START_Y = Math.round(SCREEN_SIZE.height * 0.3);
var END_X = Math.round(SCREEN_SIZE.width * 0.8);
var END_Y = Math.round(SCREEN_SIZE.height * 0.3);

// ==================== HID 检查 ====================

function checkHID() {
    try {
      if (typeof hid === 'undefined') {
            console.log("err HID模块未定义");
            return false;
      }
      
      console.log("检查HID状态...");
      var hidOn = false;
      try {
            hidOn = hid.isOn();
            console.log("HID状态: " + (hidOn ? "已开启" : "未开启"));
      } catch(e) {
            hidOn = false;
            console.log("err 检查HID状态失败: " + e);
      }
      
      if (!hidOn) {
            console.log("err HID未开启,请在AIWROK设置中开启HID功能");
            return false;
      }
      
      console.log("HID设备: " + hid.getName() + " | " + hid.getDeviceID());
      return true;
    } catch (e) {
      console.log("err HID检查失败: " + e);
      return false;
    }
}

// ==================== HID 滑动方法演示 ====================

/**
* 1. HID 标准滑动方法 swip
* @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 demoHidSwip() {
    console.log("\n========== 1. HID 标准滑动 swip ==========");
    try {
      if (typeof hid !== 'undefined' && typeof hid.swip === 'function') {
            console.log("执行HID标准滑动: (" + START_X + "," + START_Y + ") -> (" + END_X + "," + END_Y + ")");
            console.log("参数: 步数=10, 持续时间=" + DURATION + "ms, 方向=0");
            hid.swip(START_X, START_Y, END_X, END_Y, 10, DURATION, 0);
            console.log("✅ HID标准滑动执行成功");
            sleep.millisecond(1000);
            return true;
      } else {
            console.log("❌ HID模块或swip方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ HID标准滑动失败: " + e);
      return false;
    }
}

/**
* 2. HID AI智能滑动 swipAI
* 尽可能模拟人工手动滑动轨迹
* @param {number} startX - 起始X坐标
* @param {number} startY - 起始Y坐标
* @param {number} endX - 结束X坐标
* @param {number} endY - 结束Y坐标
*/
function demoHidSwipAI() {
    console.log("\n========== 2. HID AI智能滑动 swipAI ==========");
    try {
      if (typeof hid !== 'undefined' && typeof hid.swipAI === 'function') {
            console.log("执行HID AI智能滑动: (" + START_X + "," + START_Y + ") -> (" + END_X + "," + END_Y + ")");
            console.log("特点: 自动模拟人工滑动轨迹,更加自然");
            hid.swipAI(START_X, START_Y, END_X, END_Y);
            console.log("✅ HID AI智能滑动执行成功");
            sleep.millisecond(1000);
            return true;
      } else {
            console.log("❌ HID模块或swipAI方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ HID AI智能滑动失败: " + e);
      return false;
    }
}

/**
* 3. HID 滑动增强版 swipEx
* 提供更多参数的滑动控制
* @param {number} startX - 起始X坐标
* @param {number} startY - 起始Y坐标
* @param {number} endX - 结束X坐标
* @param {number} endY - 结束Y坐标
* @param {number} param1 - 参数1
* @param {number} duration - 滑动持续时间(毫秒)
* @param {number} param2 - 参数2
*/
function demoHidSwipEx() {
    console.log("\n========== 3. HID 滑动增强版 swipEx ==========");
    try {
      if (typeof hid !== 'undefined' && typeof hid.swipEx === 'function') {
            console.log("执行HID滑动增强版: (" + START_X + "," + START_Y + ") -> (" + END_X + "," + END_Y + ")");
            console.log("参数: param1=0, 持续时间=" + DURATION + "ms, param2=0");
            hid.swipEx(START_X, START_Y, END_X, END_Y, 0, DURATION, 0);
            console.log("✅ HID滑动增强版执行成功");
            sleep.millisecond(1000);
            return true;
      } else {
            console.log("❌ HID模块或swipEx方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ HID滑动增强版失败: " + e);
      return false;
    }
}

/**
* 4. HID 快速滑动 swipM
* 简化参数的快速滑动方法
* @param {number} startX - 起始X坐标
* @param {number} startY - 起始Y坐标
* @param {number} endX - 结束X坐标
* @param {number} endY - 结束Y坐标
*/
function demoHidSwipM() {
    console.log("\n========== 4. HID 快速滑动 swipM ==========");
    try {
      if (typeof hid !== 'undefined' && typeof hid.swipM === 'function') {
            console.log("执行HID快速滑动: (" + START_X + "," + START_Y + ") -> (" + END_X + "," + END_Y + ")");
            console.log("特点: 简化参数,快速执行");
            hid.swipM(START_X, START_Y, END_X, END_Y);
            console.log("✅ HID快速滑动执行成功");
            sleep.millisecond(1000);
            return true;
      } else {
            console.log("❌ HID模块或swipM方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ HID快速滑动失败: " + e);
      return false;
    }
}

/**
* 5. HID 多段滑动 swipMultiple
* 支持多个坐标点的复杂滑动轨迹
* 注意:需要使用Java数组格式
* @param {Array} points - 坐标点数组
* @param {number} param1 - 参数1
* @param {number} duration - 滑动持续时间(毫秒)
* @param {number} param2 - 参数2
*/
function demoHidSwipMultiple() {
    console.log("\n========== 5. HID 多段滑动 swipMultiple ==========");
    try {
      if (typeof hid !== 'undefined' && typeof hid.swipMultiple === 'function') {
            console.log("执行HID多段滑动");
            // 定义一个L型滑动轨迹(使用扁平数组格式)
            var points = [
                START_X, START_Y,      // 起点
                END_X, START_Y,      // 第一转折点
                END_X, END_Y         // 终点
            ];
            console.log("轨迹点: [" + points.join(",") + "]");
            console.log("参数: param1=0, 持续时间=" + DURATION + "ms, param2=0");
            
            // 尝试直接传递数组
            try {
                hid.swipMultiple(points, 0, DURATION, 0);
                console.log("✅ HID多段滑动执行成功(方式1)");
            } catch (e1) {
                console.log("⚠️ 方式1失败,尝试方式2...");
                // 如果失败,尝试使用touchDown/Move/Up组合实现多段滑动
                console.log("使用touchDown/Move/Up组合实现多段滑动");
               
                // 第一段:起点到转折点
                hid.touchDown(0, points, points);
                sleep.millisecond(100);
                hid.touchMove(0, points, points);
                sleep.millisecond(DURATION / 2);
               
                // 第二段:转折点到终点
                hid.touchMove(0, points, points);
                sleep.millisecond(DURATION / 2);
                hid.touchUp(0);
               
                console.log("✅ HID多段滑动执行成功(方式2-组合实现)");
            }
            
            sleep.millisecond(1000);
            return true;
      } else {
            console.log("❌ HID模块或swipMultiple方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ HID多段滑动失败: " + e);
      return false;
    }
}

/**
* 6. HID 鼠标滑动 mouseSwip
* 注意:此方法在某些版本中可能不可用
* @param {number} startX - 起始X坐标
* @param {number} startY - 起始Y坐标
* @param {number} endX - 结束X坐标
* @param {number} endY - 结束Y坐标
* @param {number} duration - 滑动持续时间(毫秒)
*/
function demoHidMouseSwip() {
    console.log("\n========== 6. HID 鼠标滑动 mouseSwip ==========");
    try {
      if (typeof hid !== 'undefined' && typeof hid.mouseSwip === 'function') {
            console.log("执行HID鼠标滑动: (" + START_X + "," + START_Y + ") -> (" + END_X + "," + END_Y + ")");
            console.log("参数: 持续时间=" + DURATION + "ms");
            
            // 尝试不同的参数组合
            try {
                // 方式1: 5个参数
                hid.mouseSwip(START_X, START_Y, END_X, END_Y, DURATION);
                console.log("✅ HID鼠标滑动执行成功(5参数)");
            } catch (e1) {
                console.log("⚠️ 5参数方式失败,尝试其他方式...");
                // 方式2: 使用mouseDown/mouseMove/mouseUp组合
                console.log("使用mouseDown/mouseMove/mouseUp组合实现鼠标滑动");
               
                hid.mouseDown();
                sleep.millisecond(100);
                hid.mouseMove(END_X - START_X, END_Y - START_Y, DURATION);
                sleep.millisecond(DURATION);
                hid.mouseUp();
               
                console.log("✅ HID鼠标滑动执行成功(组合方式)");
            }
            
            sleep.millisecond(1000);
            return true;
      } else {
            console.log("⚠️ HID模块或mouseSwip方法不可用,跳过此演示");
            console.log("提示:可以使用touchDown/Move/Up或swip系列方法替代");
            return false;
      }
    } catch (e) {
      console.log("❌ HID鼠标滑动失败: " + e);
      return false;
    }
}

/**
* 7. HID 触摸拖动 touchDown/Move/Up
* 通过组合触摸按下、移动、抬起实现精确拖动控制
* @param {number} startX - 起始X坐标
* @param {number} startY - 起始Y坐标
* @param {number} endX - 结束X坐标
* @param {number} endY - 结束Y坐标
* @param {number} holdTime - 按住时长(毫秒)
* @param {number} dragTime - 拖动时长(毫秒)
*/
function demoHidTouchDrag(startX, startY, endX, endY, holdTime, dragTime) {
    console.log("\n========== 7. HID 触摸拖动 touchDown/Move/Up ==========");
    try {
      if (typeof hid !== 'undefined' &&
            typeof hid.touchDown === 'function' &&
            typeof hid.touchMove === 'function' &&
            typeof hid.touchUp === 'function') {
            
            console.log("执行HID触摸拖动: (" + startX + "," + startY + ") -> (" + endX + "," + endY + ")");
            console.log("按住时长: " + holdTime + "ms, 拖动时长: " + dragTime + "ms");
            
            // 步骤1: 触摸按下
            console.log("步骤1: 触摸按下 at (" + startX + ", " + startY + ")");
            hid.touchDown(0, startX, startY);
            sleep.millisecond(holdTime);
            
            // 步骤2: 触摸移动到目标位置
            console.log("步骤2: 触摸移动到 (" + endX + ", " + endY + ")");
            hid.touchMove(0, endX, endY);
            sleep.millisecond(dragTime);
            
            // 步骤3: 触摸抬起
            console.log("步骤3: 触摸抬起");
            hid.touchUp(0);
            
            console.log("✅ HID触摸拖动执行成功");
            sleep.millisecond(1000);
            return true;
      } else {
            console.log("❌ HID模块或touchDown/Move/Up方法不可用");
            return false;
      }
    } catch (e) {
      console.log("❌ HID触摸拖动失败: " + e);
      return false;
    }
}

// ==================== 实用滑动场景演示 ====================

/**
* 场景1: 页面上下滚动(适配抖音等应用)
*/
function demoScrollUpDown() {
    console.log("\n========== 场景1: 页面上下滚动(抖音风格) ==========");
   
    // 等待应用完全启动
    smartWait("等待应用启动", DELAY_CONFIG.appStartDelay);
   
    var centerX = Math.round(SCREEN_SIZE.width * 0.5);
   
    // 向上滚动(刷下一个视频)
    console.log("👆 向上滚动 - 刷下一个视频");
    hid.swipAI(centerX, Math.round(SCREEN_SIZE.height * 0.8), centerX, Math.round(SCREEN_SIZE.height * 0.2));
    waitForContentLoad("等待视频加载");
   
    // 向下滚动(返回上一个视频)
    console.log("👇 向下滚动 - 返回上一个视频");
    hid.swipAI(centerX, Math.round(SCREEN_SIZE.height * 0.2), centerX, Math.round(SCREEN_SIZE.height * 0.8));
    waitForContentLoad("等待视频加载");
   
    // 再次向上滚动
    console.log("👆 再次向上滚动");
    hid.swipAI(centerX, Math.round(SCREEN_SIZE.height * 0.75), centerX, Math.round(SCREEN_SIZE.height * 0.25));
    waitForContentLoad("等待视频加载");
   
    console.log("✅ 页面滚动演示完成");
}

/**
* 场景2: 页面左右滑动(适配抖音等应用)
*/
function demoScrollLeftRight() {
    console.log("\n========== 场景2: 页面左右滑动(抖音风格) ==========");
   
    // 等待页面稳定
    smartWait("等待页面稳定", DELAY_CONFIG.pageLoadDelay);
   
    var centerY = Math.round(SCREEN_SIZE.height * 0.5);
   
    // 向右滑动(切换标签/页面)
    console.log("👉 向右滑动 - 切换到下一个标签");
    hid.swipAI(Math.round(SCREEN_SIZE.width * 0.2), centerY, Math.round(SCREEN_SIZE.width * 0.8), centerY);
    waitForPageLoad("等待新页面加载");
   
    // 向左滑动(返回上一个标签)
    console.log("👈 向左滑动 - 返回上一个标签");
    hid.swipAI(Math.round(SCREEN_SIZE.width * 0.8), centerY, Math.round(SCREEN_SIZE.width * 0.2), centerY);
    waitForPageLoad("等待页面恢复");
   
    console.log("✅ 左右滑动演示完成");
}

/**
* 场景3: 复杂轨迹滑动(方形轨迹)
*/
function demoComplexPath() {
    console.log("\n========== 场景3: 复杂轨迹滑动 ==========");
   
    // 等待页面就绪
    smartWait("等待页面就绪", DELAY_CONFIG.pageLoadDelay);
   
    try {
      // 使用touchDown/Move/Up组合实现复杂轨迹
      console.log("使用touchDown/Move/Up组合实现方形轨迹滑动");
      
      var centerX = Math.round(SCREEN_SIZE.width * 0.5);
      var centerY = Math.round(SCREEN_SIZE.height * 0.5);
      var radius = Math.min(SCREEN_SIZE.width, SCREEN_SIZE.height) * 0.15;
      
      // 方形轨迹的四个角点
      var points = [
            ,// 左上
            ,// 右上
            ,// 右下
            ,// 左下
               // 回到起点
      ];
      
      console.log("轨迹点数: " + points.length);
      
      // 开始绘制轨迹
      hid.touchDown(0, points, points);
      sleep.millisecond(100);
      
      for (var i = 1; i < points.length; i++) {
            console.log("移动到点 " + i + ": (" + points + ", " + points + ")");
            hid.touchMove(0, points, points);
            sleep.millisecond(500);// 每个点之间等待500ms
      }
      
      hid.touchUp(0);
      
      // 等待操作完成
      smartWait("等待轨迹操作完成", DELAY_CONFIG.operationDelay);
      
      console.log("✅ 复杂轨迹滑动演示完成");
      return true;
    } catch (e) {
      console.log("❌ 复杂轨迹滑动失败: " + e);
      return false;
    }
}

// ==================== 主函数 ====================

function main() {
    console.log("=====================================");
    console.log("AIWROK HID 滑动所有方法功能演示");
    console.log("=====================================");
    console.log("\n请确保:");
    console.log("1. HID功能已在AIWROK设置中开启");
    console.log("2. HID设备已正确连接");
    console.log("3. 当前屏幕尺寸: " + SCREEN_SIZE.width + "x" + SCREEN_SIZE.height);
    console.log("\n&#128161; 抖音使用建议:");
    console.log("   - 如果视频未加载完就滑动,请增加 contentLoadDelay 值");
    console.log("   - 如果页面切换太快,请增加 pageLoadDelay 值");
    console.log("   - 当前配置适合中等网速环境,可根据实际情况调整");
    console.log("=====================================");
   
    // 检查HID
    if (!checkHID()) {
      console.log("err HID检查失败,终止运行");
      return;
    }
   
    console.log("\n开始演示所有HID滑动方法...\n");
   
    // 提示用户准备
    console.log("&#128161; 提示:请在3秒内打开目标应用(如抖音)");
    smartWait("准备时间", 3000);
   
    // 演示所有HID滑动方法
    demoHidSwip();
    smartWait("操作间隔", DELAY_CONFIG.swipeInterval);
   
    demoHidSwipAI();
    smartWait("操作间隔", DELAY_CONFIG.swipeInterval);
   
    demoHidSwipEx();
    smartWait("操作间隔", DELAY_CONFIG.swipeInterval);
   
    demoHidSwipM();
    smartWait("操作间隔", DELAY_CONFIG.swipeInterval);
   
    demoHidSwipMultiple();
    smartWait("操作间隔", DELAY_CONFIG.swipeInterval);
   
    demoHidMouseSwip();
    smartWait("操作间隔", DELAY_CONFIG.swipeInterval);
   
    demoHidTouchDrag(START_X, START_Y, END_X, END_Y, 1000, 2000);
    smartWait("操作间隔", DELAY_CONFIG.swipeInterval);
   
    // 演示实用场景
    demoScrollUpDown();
    demoScrollLeftRight();
    demoComplexPath();
   
    console.log("\n\n=====================================");
    console.log("✅ 所有HID滑动方法演示完成!");
    console.log("=====================================");
    console.log("\n总结:");
    console.log("1. swip - 标准滑动,参数完整控制");
    console.log("2. swipAI - AI智能滑动,模拟人工轨迹");
    console.log("3. swipEx - 增强版滑动,额外参数控制");
    console.log("4. swipM - 快速滑动,简化参数");
    console.log("5. swipMultiple - 多段滑动,复杂轨迹");
    console.log("6. mouseSwip - 鼠标滑动方式");
    console.log("7. touchDown/Move/Up - 精确拖动控制");
    console.log("=====================================");
}

main();



页: [1]
查看完整版本: AIWROK软件键鼠HID滑动所有方法功能演示