 | |  |  | hid的滑动没有百分比坐标滑动吗
- // 百分比坐标滑动示例
- // 该示例演示如何使用百分比坐标进行滑动操作
- /**
- * 使用百分比坐标进行滑动的函数
- * @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) {
- // 将百分比坐标转换为实际像素坐标
- var startX = screen.percentToWidth(startXPercent);
- var startY = screen.percentToHeight(startYPercent);
- var endX = screen.percentToWidth(endXPercent);
- var endY = screen.percentToHeight(endYPercent);
-
- // 执行滑动操作
- hid.swip(startX, startY, endX, endY, duration, 0, 0);
-
- printl("已执行滑动操作: 从(" + startXPercent*100 + "%, " + startYPercent*100 + "%) 到 (" +
- endXPercent*100 + "%, " + endYPercent*100 + "%),持续时间: " + duration + "ms");
- }
- /**
- * 模拟用户常用滑动操作的函数
- */
- function commonSwipeGestures() {
- printl("=== 常用滑动操作示例 ===");
-
- // 1. 向右滑动 (例如在相册中向右切换图片)
- printl("1. 向右滑动");
- swipeWithPercentCoordinates(0.2, 0.5, 0.8, 0.5, 300);
- sleep.millisecond(1000);
-
- // 2. 向左滑动 (例如在相册中向左切换图片)
- printl("2. 向左滑动");
- swipeWithPercentCoordinates(0.8, 0.5, 0.2, 0.5, 300);
- sleep.millisecond(1000);
-
- // 3. 向上滑动 (例如向上滚动页面)
- printl("3. 向上滑动");
- swipeWithPercentCoordinates(0.5, 0.8, 0.5, 0.2, 500);
- sleep.millisecond(1000);
-
- // 4. 向下滑动 (例如向下滚动页面)
- printl("4. 向下滑动");
- swipeWithPercentCoordinates(0.5, 0.2, 0.5, 0.8, 500);
- sleep.millisecond(1000);
-
- // 5. 从屏幕底部向上滑动 (例如打开通知栏)
- printl("5. 从底部向上滑动");
- swipeWithPercentCoordinates(0.5, 0.9, 0.5, 0.1, 800);
- sleep.millisecond(1000);
-
- printl("所有滑动操作演示完毕");
- }
- /**
- * 自定义滑动操作函数
- * @param {string} direction - 滑动方向 ("up", "down", "left", "right")
- * @param {number} duration - 滑动持续时间(毫秒)
- */
- function customSwipe(direction, duration) {
- printl("执行自定义滑动: " + direction);
-
- switch(direction) {
- case "up":
- swipeWithPercentCoordinates(0.5, 0.7, 0.5, 0.3, duration);
- break;
- case "down":
- swipeWithPercentCoordinates(0.5, 0.3, 0.5, 0.7, duration);
- break;
- case "left":
- swipeWithPercentCoordinates(0.7, 0.5, 0.3, 0.5, duration);
- break;
- case "right":
- swipeWithPercentCoordinates(0.3, 0.5, 0.7, 0.5, duration);
- break;
- default:
- printl("未知的滑动方向: " + direction);
- }
- }
- // 使用示例
- printl("=== 百分比坐标滑动示例 ===");
- // 检查HID是否开启
- if (hid.isOn()) {
- printl("HID设备已开启");
-
- // 演示常用滑动操作
- commonSwipeGestures();
-
- // 演示自定义滑动操作
- printl("\n=== 自定义滑动操作 ===");
- customSwipe("up", 400);
- sleep.millisecond(500);
- customSwipe("down", 400);
- sleep.millisecond(500);
- customSwipe("left", 300);
- sleep.millisecond(500);
- customSwipe("right", 300);
-
- printl("\n所有示例执行完毕");
- } else {
- printl("错误: HID设备未开启,请先开启HID设备");
- }
复制代码
| |  | |  |
|