adb 与pad 交互方法

event

python 复制代码
import requests
import time
import random
import os

# http://fspcdiy.d33173.chshtzs.com/action.php
# 连接设备(有线直接连接,无线需先执行adb tcpip 5555)
os.system('adb devices')  # 验证连接


# 定义点击函数
def tap(x, y):
    os.system(f'adb shell input tap {x} {y}')


def check_status():
    # 添加随机参数和禁用缓存的请求头
    timestamp = int(time.time())
    rand = random.randint(0, 9999)
    url = f"http://fspcdiy.d33173.chshtzs.com/do.php?cmd=status&_={timestamp}{rand}"

    headers = {
        'Cache-Control': 'no-cache, no-store, must-revalidate',
        'Pragma': 'no-cache',
        'Expires': '0'
    }

    try:
        response = requests.get(url, headers=headers)
        if response.status_code == 200:
            content = response.text.strip()
            if content.startswith("Current action: "):
                value = content[len("Current action: "):].strip()
                print('test:' + value)
                return value
        return None
    except requests.RequestException as e:
        print(f"请求出错: {e}")
        return None


def delete_action():
    # 同样为delete请求添加防缓存措施
    timestamp = int(time.time())
    rand = random.randint(0, 9999)
    delete_url = f"http://fspcdiy.d33173.chshtzs.com/do.php?cmd=delete&_={timestamp}{rand}"

    headers = {
        'Cache-Control': 'no-cache, no-store, must-revalidate',
        'Pragma': 'no-cache',
        'Expires': '0'
    }

    try:
        requests.get(delete_url, headers=headers)
    except requests.RequestException as e:
        print(f"删除操作出错: {e}")


def main():
    while True:
        value = check_status()

        if value and value != "No action stored":
            if value == "UP":
                print("UP")
                # 向上
                tap(1719, 510)
                time.sleep(3)
                delete_action()
            elif value == "DOWN":
                print("DOWN")
                # 向下
                tap(1719, 688)
                time.sleep(3)
                delete_action()
            elif value == "LEFT":
                print("LEFT")
                # 向左
                tap(1626, 606)
                time.sleep(3)
                delete_action()
            elif value == "RIGHT":
                print("RIGHT")
                # 向右
                tap(1800, 596)
                time.sleep(3)
                delete_action()
            elif value == "CLAMP":
                print("CLAMP")
                # 夹子
                tap(1000, 1132)
                time.sleep(3)
                delete_action()
            elif value == "FOOD1":
                print("FOOD1")
                # 动作1 上
                tap(285, 521)
                time.sleep(3)
                delete_action()
            elif value == "FOOD2":
                print("FOOD2")
                # 动作2 下
                tap(290, 704)
                time.sleep(3)
                delete_action()
            elif value == "FOOD3":
                print("FOOD3")
                # 动作3 左
                tap(195, 607)
                time.sleep(3)
                delete_action()
            elif value == "FOOD4":
                print("FOOD4")
                # 动作4 右
                tap(377, 608)
                time.sleep(3)
                delete_action()
            else:
                print(f"未知动作: {value}")

        time.sleep(3)


if __name__ == "__main__":
    main()

do.php

php 复制代码
<?php
// 定义存储文件路径
$storage_file = 'shared_action.txt';

if (isset($_GET['action'])) {
    file_put_contents($storage_file, $_GET['action']);
    echo "Action stored: " . htmlspecialchars($_GET['action']);
} elseif (isset($_GET['cmd'])) {
    $command = strtolower($_GET['cmd']);
    
    if ($command === 'status') {
        if (file_exists($storage_file)) {
            echo "Current action: " . htmlspecialchars(file_get_contents($storage_file));
        } else {
            echo "No action stored";
        }
    } elseif ($command === 'delete') {
        if (file_exists($storage_file)) {
            unlink($storage_file);
        }
        echo "Action deleted successfully";
    } else {
        echo "Invalid command";
    }
} else {
    // 显示使用说明
    echo "<h1>Action Management System</h1>";
    // ... 其余HTML代码 ...
}
?>
相关推荐
·云扬·2 天前
MySQL Binlog落盘机制深度解析:性能与安全性的平衡艺术
android·mysql·adb
天马37982 天前
MySql9 免安装版_配置和启动_MySql9安装
adb·mysql9 免安装版·mysql9安装
·云扬·2 天前
MySQL Binlog 配置指南与核心作用解析
数据库·mysql·adb
darling3312 天前
mysql 自动备份以及远程传输脚本,异地备份
android·数据库·mysql·adb
Remember_9932 天前
MySQL 索引详解:从原理到实战优化
java·数据库·mysql·spring·http·adb·面试
多多*3 天前
2月3日面试题整理 字节跳动后端开发相关
android·java·开发语言·网络·jvm·adb·c#
数据蜂巢3 天前
MySQL 8.0 生产环境备份脚本 (Percona XtraBackup 8.0+)
android·mysql·adb
vistaup4 天前
通过ADB 触发gc
adb
Tangcan-4 天前
【MySQL】 事务
数据库·mysql·adb
qinyia4 天前
在Ubuntu 22.04.5 LTS上安装MySQL 8并设置root密码的完整协作流程
mysql·ubuntu·adb