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

问题描述 投票:0回答:2

我在表达这个标题时遇到了一些困难,但请允许我解释一下。

PyAutoGUI
i 允许您通过控制鼠标和键盘来自动化任何事情。但是,如果
pyAutoGUI
脚本正在运行,则意味着 you 无法触摸键盘/鼠标,因为它是由脚本控制的。

我的问题是如何自动化程序(这不是窗口程序,例如 Photoshop、Steam 或其他非 Windows 程序[澄清一下,当我说非 Windows 程序时,我指的是记事本、画图等默认程序) ])无需放弃键盘和鼠标。我知道有

PyWinAuto
,但这仅适用于 Windows 程序,例如
notepad
)。这意味着您可以让脚本在后台运行,同时您可以在计算机上执行其他操作。

一个可能的解决方案是在虚拟机中运行脚本,但我正在寻找一种不必这样做的解决方案。有没有一个 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++
}
python python-3.x automation pyautogui
2个回答
1
投票

A photoshop API 现已于 2020 年推出,我还发现了这篇post,其中有一个视频演示,详细介绍了如何使用 python 控制 Photoshop。从简短观看视频来看,代码似乎在 Windows 后端执行,因此您可以在代码运行时自由使用鼠标和键盘,而不会受到任何干扰。


0
投票

我也在尝试执行此操作,但通过 Power Automate Desktop 生成的脚本使用其他软件。他们目前没有办法让脚本在不接管鼠标和键盘的情况下运行,所以我正在寻找解决方法。我正在处理的脚本与来自不同开发人员的几种不同软件进行交互。我希望有某种方法可以让我的鼠标和键盘有一个单独的数字版本,当我使用物理版本时,脚本可以使用它。有什么想法吗?也许我可以以某种方式让它使用屏幕键盘,并以某种方式将其与物理键盘分离?

© www.soinside.com 2019 - 2024. All rights reserved.