怎么从悬浮窗启动脚本

HAMI_7760954542 · 1 天前

回答

Hamibot AI
1
· 1 天前

从悬浮窗启动脚本有两种方式:

方式一:使用 Hamibot 客户端自带悬浮窗

步骤 操作
1 打开 Hamibot 客户端
2 进入「设置」→ 开启「悬浮窗」
3 授权悬浮窗权限
4 屏幕上会出现蓝色悬浮窗图标
5 点击悬浮窗 → 选择脚本 → 运行

方式二:自定义悬浮窗启动脚本

编写一个脚本,创建悬浮窗按钮来启动其他脚本:

// 文档地址 https://docs.hamibot.com/

auto.waitFor();

// 创建悬浮窗
var w = floaty.window(
    <vertical bg="#E6000000" padding="12">
        <text text="脚本启动器" textColor="#4CAF50" textSize="14sp" gravity="center"/>
        <button id="btn1" text="运行脚本A" margin="8"/>
        <button id="btn2" text="运行脚本B" margin="8"/>
        <button id="btnClose" text="关闭悬浮窗" margin="8" style="Widget.AppCompat.Button.Borderless"/>
    </vertical>
);

// 设置位置
w.setPosition(50, 100);

// 按钮点击事件
w.btn1.click(function() {
    toastLog("启动脚本A...");
    // 方式1:通过脚本名称启动(需脚本已安装)
    engines.execScriptFile("/sdcard/脚本A.js");
    
    // 方式2:通过脚本内容启动
    // engines.execScript("脚本A的代码内容");
});

w.btn2.click(function() {
    toastLog("启动脚本B...");
    engines.execScriptFile("/sdcard/脚本B.js");
});

w.btnClose.click(function() {
    toastLog("关闭悬浮窗");
    w.close();
    exit();
});

// 保持悬浮窗显示
setInterval(function() {}, 1000);

启动脚本的方法

方法 用途 示例
engines.execScriptFile(path) 启动本地脚本文件 engines.execScriptFile("/sdcard/test.js")
engines.execScript(code) 启动脚本代码字符串 engines.execScript("toast('hello')")
engines.execAutoFile(path) 启动录制文件 engines.execAutoFile("/sdcard/test.auto")

注意事项

要点 说明
悬浮窗权限 需要授权才能显示
脚本路径 确保脚本文件存在且路径正确
保持运行 需要 setInterval 防止悬浮窗关闭
多脚本运行 可同时运行多个脚本,互不干扰

参考文档:https://docs.hamibot.com/

ℹ️ 内容由 AI 生成,可能不准确,请注意核实