更新 src/main.rs

This commit is contained in:
revin 2024-11-12 21:09:41 +08:00
parent 57b993e8f9
commit d6f05cb93e

View File

@ -17,13 +17,26 @@ fn main() -> PyResult<()> {
// 定义要点击的鼠标位置坐标
let positions = [(2828, 1087), (2515, 102), (3186, 1479)];
for (x, y) in positions {
for (x, y) in &positions {
// 导入pyautogui模块并调用click方法
let click_result = Python::with_gil(|py| -> PyResult<()> {
let pyautogui_module = py.import("pyautogui")?;
let click = pyautogui_module.getattr("click")?;
click.call1((x, y))?;
Ok(())
// 尝试点击,并捕获可能的 FailSafeException
match click.call1((*x, *y)) {
Ok(_) => Ok(()),
Err(e) => {
if e.is_instance_of::<pyo3::exceptions::PyRuntimeError>(py) {
// 如果是 FailSafeException打印错误信息并继续下一个位置
eprintln!("FailSafeException triggered at ({}, {}). Continuing...", x, y);
} else {
// 其他类型的错误重新抛出
return Err(e);
}
Ok(())
},
}
});
match click_result {