From 8c9cc4db88ecb3b0192aefef8c81af56b597b067 Mon Sep 17 00:00:00 2001 From: Oliver Hartmann Date: Sun, 14 Mar 2021 14:38:24 +0100 Subject: [PATCH] Global conf and key press wait config option --- config.yaml | 1 + src/config.py | 6 +++++- src/sendkeys.py | 5 +++-- tests/test_keyboard.py | 8 ++++---- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/config.yaml b/config.yaml index d732fa9..355b4bf 100644 --- a/config.yaml +++ b/config.yaml @@ -1,6 +1,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 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/config.py b/src/config.py index 63fd46f..0214789 100644 --- a/src/config.py +++ b/src/config.py @@ -1,6 +1,10 @@ import yaml +conf = None + def read_config(filename): with open(filename, 'r') as f: - return yaml.safe_load(f) + global conf + conf = yaml.safe_load(f) + return conf diff --git a/src/sendkeys.py b/src/sendkeys.py index 1da6959..60d02d0 100644 --- a/src/sendkeys.py +++ b/src/sendkeys.py @@ -1,6 +1,7 @@ from pywinauto.application import Application from src import data +from src import config def send_text(text: str) -> None: @@ -8,7 +9,7 @@ def send_text(text: str) -> None: app.connect(title='Path of Exile') win = app.window_(title_re='Path of Exile') text = escape_mods(text) - win.TypeKeys('{ENTER}^A{DELETE}' + text + '{ENTER}', with_spaces=True) + win.TypeKeys('{ENTER}^A{DELETE}' + text + '{ENTER}', with_spaces=True, pause=config.conf['General']['after_sendkeys_key_wait']) def escape_mods(text: str) -> str: @@ -22,7 +23,7 @@ def send_to(user: str, text: str) -> None: send_text(f'@{user} {text}') -def send_to_format(type: str, message: data.Message, conf: dict()) -> None: +def send_to_format(type: str, message: data.Message) -> None: """Send a message defined in the conf dict to a user Args: diff --git a/tests/test_keyboard.py b/tests/test_keyboard.py index 1a5f2f4..e4b5af1 100644 --- a/tests/test_keyboard.py +++ b/tests/test_keyboard.py @@ -17,7 +17,7 @@ def test_pickup(): text = '2021/03/08 23:24:52 17931875 bb3 [INFO Client 1492] @From Sinusal: Hi, I would like to buy your level 21 23% Vaal Impurity of Lightning ' \ 'listed for 18 chaos in Ritual (stash tab "$"; position: left 22, top 5)' message = data.Message.from_text(text) - sendkeys.send_to_format('pickup', message, conf) + sendkeys.send_to_format('pickup', message) def test_wait(): @@ -26,7 +26,7 @@ def test_wait(): text = '2021/03/08 23:24:52 17931875 bb3 [INFO Client 1492] @From Sinusal: Hi, I would like to buy your level 21 23% Vaal Impurity of Lightning ' \ 'listed for 18 chaos in Ritual (stash tab "$"; position: left 22, top 5)' message = data.Message.from_text(text) - sendkeys.send_to_format('wait', message, conf) + sendkeys.send_to_format('wait', message) def test_ty(): @@ -35,7 +35,7 @@ def test_ty(): text = '2021/03/08 23:24:52 17931875 bb3 [INFO Client 1492] @From Sinusal: Hi, I would like to buy your level 21 23% Vaal Impurity of Lightning ' \ 'listed for 18 chaos in Ritual (stash tab "$"; position: left 22, top 5)' message = data.Message.from_text(text) - sendkeys.send_to_format('ty', message, conf) + sendkeys.send_to_format('ty', message) def test_sold(): @@ -44,4 +44,4 @@ def test_sold(): text = '2021/03/08 23:24:52 17931875 bb3 [INFO Client 1492] @From Sinusal: Hi, I would like to buy your level 21 23% Vaal Impurity of Lightning ' \ 'listed for 18 chaos in Ritual (stash tab "$"; position: left 22, top 5)' message = data.Message.from_text(text) - sendkeys.send_to_format('sold', message, conf) + sendkeys.send_to_format('sold', message)