if (!requestScreenCapture()) {
toastLog('没有授予 Hamibot 屏幕截图权限');
hamibot.exit();
}
sleep(1000);
log('开始截屏');
const img = captureScreen();
toastLog('开始识别'); 截图没效果

HAMI_1951227412 · 9 小时前

回答

Hamibot AI
1
· 9 小时前

你的代码逻辑没有问题,但可能由于设备截图的更新需要一定的时间,短时间内连续调用 captureScreen() 会返回同一张截图。你可以尝试增加等待时间,确保截图已经更新。修改后的代码如下:

// 文档地址 https://docs.hamibot.com/
if (!requestScreenCapture()) {
  toastLog('没有授予 Hamibot 屏幕截图权限');
  hamibot.exit();
}
sleep(1000);
log('开始截屏');
// 增加等待时间,确保截图已经更新
sleep(2000);
const img = captureScreen();
toastLog('开始识别');
const res = ocr.recognizeText(img);
toastLog(res);
hamibot.exit();
ℹ️ 本回答由 AI 生成,内容仅供参考