问题
I'm new to pywinauto
and I'm creating several notepad windows and typing a text in all of them. However, this is not dependent on each other, so this can be run concurrently using threads.
However, when I try to do the same, the text get messed up because there are several threads trying to access the type_keys()
method at the same time. Is there any way I can achieve the same concurrently?
回答1:
There is another method .set_text("...")
that doesn't require window to be in focus. It's available for edit box only.
.type_keys()
or .click_input()
is not a good choice for concurrent automation or for a locked machine / minimized RDP. More details can be found in Remote Execution Guide.
回答2:
you can also try this importing keybord from pywinauto and the send the line you would like to send this is a small exemple :
from pywinauto import application
from pywinauto import keyboard
app = application.Application()
app.start("Notepad.exe")
keyboard.SendKeys('hello')
with this code you will open Notepade and write hello in Notepad , I just created to .py file and both have same code and I did call them on main file and worked perfect I created A.py and put code on it and I created B.py and put same code and in C.py I did import A , import B it and run it it did open 2 Notpad and wrote the text look for this example : A.py
from pywinauto import application
from pywinauto import keyboard
app = application.Application()
app.start("Notepad.exe")
keyboard.SendKeys('hello')
B.py
from pywinauto import application
from pywinauto import keyboard
app = application.Application()
app.start("Notepad.exe")
keyboard.SendKeys('hello friends',with_spaces=True)
C.py
import A,B
and run C.py make sur all the files are saved in same folder
来源:https://stackoverflow.com/questions/55378193/locking-in-multi-threaded-pywinauto-send-keys