const img = captureScreen();
toastLog('开始识别');
const res = ocr.recognize(img);
log(res);
报错
11:10:25.624/D: { [JavaException: java.lang.SecurityException: No screen capture permission] fileName: '<init>', lineNumber: 29 }
回答
这个错误提示表明你的脚本没有获得屏幕截图权限。请确保你已经正确请求了屏幕截图权限,并且用户已经授予了该权限。以下是一个示例代码,展示如何正确请求屏幕截图权限并进行文字识别:
// 文档地址 https://docs.hamibot.com/
auto.waitFor();
if (!requestScreenCapture()) {
toastLog('没有授予 Hamibot 屏幕截图权限');
hamibot.exit();
}
sleep(1000);
log('开始截屏');
const img = captureScreen();
toastLog('开始识别');
const res = ocr.recognize(img);
log(res);
hamibot.exit();
ℹ️ 本回答由 AI 生成,内容仅供参考