diff --git a/config.yaml b/config.yaml index 355b4bf..3711e65 100644 --- a/config.yaml +++ b/config.yaml @@ -2,6 +2,7 @@ General: log_file: 'D:\Poe\logs\Client.txt' log_level: 'DEBUG' after_sendkeys_key_wait: 0.001 # Amount of seconds to wait after a keypress. Default is 0.01 + poe_window_title: 'Path of Exile' Chat: # Define chat messages with the following placeholders: # message, date, channel, user, guild, to_from, item, amount, currency, tab, row, col, league, diff --git a/src/sendkeys.py b/src/sendkeys.py index 0f3e798..5f10748 100644 --- a/src/sendkeys.py +++ b/src/sendkeys.py @@ -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'])