Catch the window title not found exception

This commit is contained in:
2021-03-20 14:40:47 +01:00
parent 36589fc68f
commit 990b001730
2 changed files with 8 additions and 2 deletions

View File

@@ -1,13 +1,18 @@
from pywinauto.application import Application
from pywinauto.findwindows import ElementNotFoundError
from src import data
from src import config
def send_text(text: str) -> None:
app = Application()
app.connect(title='Path of Exile')
win = app.window(title_re='Path of Exile')
try:
app.connect(title=config.conf['General']['poe_window_title'])
except ElementNotFoundError:
data.log.warning(f'Title {config.conf["General"]["poe_window_title"]} not found')
return
win = app.window(title_re=config.conf['General']['poe_window_title'])
text = escape_mods(text)
win.type_keys('{ENTER}^A{DELETE}' + text + '{ENTER}', with_spaces=True, pause=config.conf['General']['after_sendkeys_key_wait'])