-->

how to switch between two application using pywina

2019-07-30 17:17发布

问题:

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)\eSpeak\eSpeakedit.exe")

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

回答1:

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)\eSpeak\eSpeakedit.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