如何在不丧失键盘/鼠标控制的情况下实现自动化(类似于selenium的受控窗口)

2024-05-19 19:47:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我在这个标题的措辞上有点困难,但请允许我解释一下。PyAutoGUI我允许您通过控制鼠标和键盘来实现任何操作的自动化。但是,如果pyAutoGUI脚本正在运行,则意味着您不能触摸键盘/鼠标,因为它是由脚本控制的。你知道吗

我的问题是,你如何能在不放弃键盘和鼠标的情况下,自动化一个程序(不是窗口程序,例如Photoshop、Steam或其他非windows程序)。我知道有PyWinAuto,但那只适用于像notepad这样的windows程序。意思是你可以让脚本在后台运行,而你可以在你的电脑上做其他事情。你知道吗

一个可能的解决方案是在虚拟机中运行脚本,但我正在寻找一个解决方案,我不必这样做。有一个python模块允许我这么做吗?我想与photoshop的界面进行交互,而不必坐在那里看着脚本接管我的电脑并完成它的工作。你知道吗


pyAutoGui的示例场景:

// I run the python script.
// I can no longer touch the keyboard and mouse because
// if I do, it will mess up the script. Meaning the active window on my
// computer is photoshop and I am forced to look at the endless
// while loop
Open photoshop
i = 0
while(1) {
    mouse click x=i y=i
    type "hello world"
    i++
}

我正在寻求的解决方案示例:

// I run the python script.
// A controlled window (similar to a selenium browser) opens up.
// In Selenium you can minimise a selenium browser while its doing its
// automated tasks and do whatever you wish.
//
// I minimise the controlled window and start doing my own thing while
// in the controlled window, its opens photoshop and does the while loop
Open photoshop
i = 0
while(1) {
    mouse click x=i y=i
    type "hello world"
    i++
}

Tags: andthe程序脚本windowsscript鼠标键盘