更新 src/main.rs
This commit is contained in:
parent
57b993e8f9
commit
d6f05cb93e
17
src/main.rs
17
src/main.rs
@ -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))?;
|
||||
|
||||
// 尝试点击,并捕获可能的 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user