up
This commit is contained in:
commit
4e204b60e2
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "scanxrs"
|
||||
version = "0.1.0"
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "scanxrs"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
18
redme.txt
Normal file
18
redme.txt
Normal file
@ -0,0 +1,18 @@
|
||||
C:\pytest>conda env list
|
||||
|
||||
|
||||
pymain-dev C:\condas\envs\pymain-dev
|
||||
pytest-devs C:\condas\envs\pytest-devs
|
||||
|
||||
conda activate pymain-dev
|
||||
|
||||
|
||||
python ScanwX1.py
|
||||
|
||||
|
||||
|
||||
C:\pytest\scanxrs\target\debug> .\scanxrs.exe
|
||||
|
||||
|
||||
cargro run 或者 .\scanxrs.exe
|
||||
|
40
scanXpy/ScanwX1.py
Normal file
40
scanXpy/ScanwX1.py
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
#扫描仪扫描自动点击鼠标脚本
|
||||
import pyautogui
|
||||
import time
|
||||
|
||||
def click(x, y, interval):
|
||||
# 点击指定位置的鼠标
|
||||
pyautogui.click(x, y)
|
||||
|
||||
# 等待指定的时间间隔
|
||||
time.sleep(interval)
|
||||
|
||||
# 定义一个包含点击位置和时间间隔的列表
|
||||
clicks = [(2828, 1087, 1),(2515, 102, 1), (3186, 1479, 1)]
|
||||
|
||||
# 遍历列表,依次点击每个位置
|
||||
for x, y, interval in clicks:
|
||||
click(x, y, interval)
|
||||
|
||||
|
||||
|
||||
'''
|
||||
|
||||
#检查鼠标位置函数备用
|
||||
def wait_and_detect_mouse_position():
|
||||
# 等待 2 秒
|
||||
time.sleep(4)
|
||||
|
||||
# 检测鼠标位置
|
||||
mouse_position = pyautogui.position()
|
||||
|
||||
return mouse_position
|
||||
|
||||
# 调用函数
|
||||
mouse_position = wait_and_detect_mouse_position()
|
||||
print("鼠标位置:", mouse_position)
|
||||
|
||||
|
||||
#鼠标位置: Point(x=2828, y=1087) , Point(x=2515, y=102), Point(x=3186, y=1479)
|
||||
'''
|
1
scanXpy/mouse_position/.gitignore
vendored
Normal file
1
scanXpy/mouse_position/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
7
scanXpy/mouse_position/Cargo.lock
generated
Normal file
7
scanXpy/mouse_position/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "mouse_position"
|
||||
version = "0.1.0"
|
8
scanXpy/mouse_position/Cargo.toml
Normal file
8
scanXpy/mouse_position/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "mouse_position"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
19
scanXpy/mouse_position/src/main.rs
Normal file
19
scanXpy/mouse_position/src/main.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use std::ffi::OsString;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
const PYTHON_INTERPRETER_PATH: &str =r"C:\\condas\\envs\\pymain-dev\\python.exe";
|
||||
const PYTHON_SCRIPT_PATH: &str = "C:\\pytest\\mouse_position\\src\\wait_and_detect_mouse_position.py";
|
||||
|
||||
let output = Command::new(OsString::from(PYTHON_INTERPRETER_PATH))
|
||||
.arg(PYTHON_SCRIPT_PATH)
|
||||
.output()
|
||||
.expect("Failed to execute Python script");
|
||||
|
||||
// 直接打印Python脚本的原始输出
|
||||
println!("Python脚本鼠标位置坐标:{}", String::from_utf8_lossy(&output.stdout));
|
||||
|
||||
// 如果需要的话,也可以打印标准错误输出(stderr)
|
||||
//println!("Python脚本的标准错误输出:{}", String::from_utf8_lossy(&output.stderr));
|
||||
}
|
||||
|
23
scanXpy/mouse_position/src/wait_and_detect_mouse_position.py
Normal file
23
scanXpy/mouse_position/src/wait_and_detect_mouse_position.py
Normal file
@ -0,0 +1,23 @@
|
||||
import pyautogui
|
||||
import time
|
||||
|
||||
#检测鼠标位置
|
||||
|
||||
|
||||
|
||||
def wait_and_detect_mouse_position():
|
||||
# 等待 4 秒(根据Rust代码中等待的时间调整)
|
||||
time.sleep(4)
|
||||
|
||||
# 检测鼠标位置
|
||||
mouse_position = pyautogui.position()
|
||||
|
||||
# 返回鼠标位置作为元组,以便Rust端更容易解析
|
||||
return mouse_position.x, mouse_position.y
|
||||
|
||||
# 直接执行函数并打印结果
|
||||
mouse_x, mouse_y = wait_and_detect_mouse_position()
|
||||
#print(f"鼠标位置:({mouse_x}, {mouse_y})")
|
||||
|
||||
# 同时,为了Rust能够捕获输出,将鼠标位置作为CSV格式输出
|
||||
print(f"mouse_x, mouse_y: {mouse_x},{mouse_y}")
|
8
scanXpy/python env导包指南.txt
Normal file
8
scanXpy/python env导包指南.txt
Normal file
@ -0,0 +1,8 @@
|
||||
查看 当前虚拟环境 conda env list
|
||||
|
||||
激活环境 conda activate pymain-dev
|
||||
|
||||
查看包 pip list
|
||||
|
||||
导出包 python -m pip freeze > requirements.txt
|
||||
安装包 pip install -r requirements.txt
|
10
scanXpy/requirements.txt
Normal file
10
scanXpy/requirements.txt
Normal file
@ -0,0 +1,10 @@
|
||||
MouseInfo==0.1.3
|
||||
pillow==10.2.0
|
||||
PyAutoGUI==0.9.54
|
||||
PyGetWindow==0.0.9
|
||||
PyMsgBox==1.0.9
|
||||
pyperclip==1.8.2
|
||||
PyRect==0.2.0
|
||||
PyScreeze==0.1.30
|
||||
pytweening==1.2.0
|
||||
threadpool==1.3.2
|
32
src/main.rs
Normal file
32
src/main.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use std::process::Command;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
fn main() {
|
||||
// Python解释器路径
|
||||
let python_interpreter = r"C:\\condas\envs\\pymain-dev\\python.exe";
|
||||
// Python脚本路径
|
||||
let python_script_path = "C:\\pytest\\scanxrs\\src\\script.py";
|
||||
let clicks = [(2828, 1087, 1),(2515, 102, 1), (3186, 1479, 1)];
|
||||
|
||||
// 定义一个函数,用于启动Python子进程执行点击操作
|
||||
fn run_python_click_command(x: u32, y: u32, interval: u32, python_interpreter: &str, python_script_path: &str) {
|
||||
let command = format!("{python_interpreter} {python_script_path} {x} {y}");
|
||||
let output = Command::new("cmd")
|
||||
.arg("/C")
|
||||
.arg(command)
|
||||
.output()
|
||||
.expect("Failed to execute Python script");
|
||||
|
||||
// 打印输出以确认执行结果(可选)
|
||||
println!("Ok: {}", String::from_utf8_lossy(&output.stdout));
|
||||
|
||||
// 模拟等待指定时间间隔
|
||||
sleep(Duration::from_millis(interval as u64 * 1000));
|
||||
}
|
||||
|
||||
// 遍历点击列表,依次执行点击操作
|
||||
for (x, y, interval) in clicks {
|
||||
run_python_click_command(x, y, interval, python_interpreter, python_script_path);
|
||||
}
|
||||
}
|
8
src/script.py
Normal file
8
src/script.py
Normal file
@ -0,0 +1,8 @@
|
||||
import sys
|
||||
import pyautogui
|
||||
import time
|
||||
def click(x, y):
|
||||
pyautogui.click(x, y)
|
||||
|
||||
x, y = map(int, sys.argv[1:3])
|
||||
click(x, y)
|
Loading…
Reference in New Issue
Block a user