【发布时间】:2021-01-08 12:36:12
【问题描述】:
我需要编写一个应用程序,它主要关注给定的 Windows 窗口标题并在记事本中复制粘贴数据。我已经设法用 pygetwindow 和 pyautogui 实现了它,但它有问题:
import pygetwindow as gw
import pyautogui
# extract all titles and filter to specific one
all_titles = gw.getAllTitles()
titles = [title for title in all_titles if 'title' in title]
window = gw.getWindowsWithTitle(titles[0])[0].activate()
pyautogui.hotkey('ctrl', 'a')
pyautogui.hotkey('ctrl', 'c')
使用Spyder,激活时偶尔会报如下错误:
PyGetWindowException: Error code from Windows: 126 - The specified module could not be found.
此外,我有兴趣在不影响在机器上工作的用户的情况下执行此过程。激活基本上使窗口弹出到前面。此外,最好不要依赖操作系统,但我还没有找到任何东西。
我尝试过 pywinauto,但 SetFocus() 方法不起作用(它有问题,已记录)。
有没有其他方法可以使整个过程不可见且更容易?
【问题讨论】:
标签: python-3.x process