如何使用 pywinauto 0.5.4 在两个应用程序之间切换 [英] how to switch between two application using pywinauto 0.5.4

查看:48
本文介绍了如何使用 pywinauto 0.5.4 在两个应用程序之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动执行一项任务,即从记事本中逐行复制每一行并将其粘贴到应用程序中,然后单击一个按钮,然后将输出复制到第三个记事本文件.
我正在使用 pywinauto用于此自动化的 0.5.4 的 python,我没有得到有关如何在不同应用程序之间切换的任何帮助

I am trying to automate a task of copying every single line one by one from Notepad and pasting it the application and then clicking at a button and then copying the output to a third notepad file.
I am using pywinauto 0.5.4 of python for this automation and I am not getting any help on how to switch between different application

from pywinauto import application

app = application.Application()
app = application.Application()
app.start("Notepad.exe")
app.start("C:Program Files (x86)eSpeakeSpeakedit.exe")

我正在使用此代码启动两个应用程序.如何在这两个应用之间随意切换?

I am using this code for starting two apps. How to switch between these two application at will?

推荐答案

这段代码应该可以解决问题:

This code should do the trick:

from pywinauto import application

app = application.Application()
app2 = application.Application()
app.start("Notepad.exe")
app2.start(r"C:Program Files (x86)eSpeakeSpeakedit.exe")

# switch to Notepad
app.UntitledNotepad.SetFocus()
# select and copy next line (this is not the only way, just for example)
app.UntitledNotepad.Edit.TypeKeys('{DOWN}{HOME}+{END}^c')

 # switch to your app
app2.SpeakEditWindowTitle.SetFocus()
# paste somewhere

这篇关于如何使用 pywinauto 0.5.4 在两个应用程序之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆