From d67b57496948d58dbf2ccb0a25fad08a28c79a3b Mon Sep 17 00:00:00 2001 From: Oliver Hartmann Date: Sun, 14 Mar 2021 13:20:22 +0100 Subject: [PATCH] Added sendkeys module. --- config.yaml | 4 ++++ requirements.txt | 3 ++- src/sendkeys.py | 32 ++++++++++++++++++++++++++++++++ tests/test_keyboard.py | 25 +++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/sendkeys.py create mode 100644 tests/test_keyboard.py diff --git a/config.yaml b/config.yaml index 45f3df5..d191493 100644 --- a/config.yaml +++ b/config.yaml @@ -1,6 +1,10 @@ General: log_file: 'D:\Poe\logs\Client.txt' log_level: 'DEBUG' +Chat: + pickup: 'Your item {item} for {amount} {currency} is ready to pickup.' + wait: 'I am currently busy. Please wait.' + ty: 'Thank you and good luck.' Parser: re_log: '(?P\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d) (\d+) (\S+) \[(?P\S+) (\S+) (\d+)\] (?P[#@%$&]?)(?PTo|From)?\s?(?P<\S+>)? ?(?P[^:]+): (?P.*)' re_trade: 'Hi, I would like to buy your (?P.+) listed for (?P\d+) (?P\S+) in (?P\S+) \(stash tab "(?P.+)"; position: left (?P\d+), top (?P\d+)\)' diff --git a/requirements.txt b/requirements.txt index cfd1875..68dfdbd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pytest==6.2.2 -pyyaml==5.4.1 \ No newline at end of file +pyyaml==5.4.1 +pywinauto==0.6.8 \ No newline at end of file diff --git a/src/sendkeys.py b/src/sendkeys.py new file mode 100644 index 0000000..3e9e8e3 --- /dev/null +++ b/src/sendkeys.py @@ -0,0 +1,32 @@ + +from pywinauto.application import Application + + +def send_text(text: str) -> None: + app = Application() + app.connect(title='Path of Exile') + win = app.window_(title_re='Path of Exile') + win.TypeKeys('{ENTER}^A{DELETE}' + text + '{ENTER}', with_spaces=True) + + +def send_to(user: str, text: str) -> None: + send_text(f'@{user} {text}') + + +def invite(user: str) -> None: + send_text(f'/invite {user}') + + +def send_ty(user: str, conf: dict) -> None: + send_to(user, conf['Chat']['ty']) + + +def send_wait(user: str, conf: dict) -> None: + send_to(user, conf['Chat']['wait']) + + +def send_pickup(user: str, item: str, amount: int, currency: str, conf: dict) -> None: + text = conf['Chat']['pickup'].replace('{item}', item) + text = text.replace('{amount}', str(amount)) + text = text.replace('{currency}', currency) + send_to(user, text) diff --git a/tests/test_keyboard.py b/tests/test_keyboard.py new file mode 100644 index 0000000..6ad1a2b --- /dev/null +++ b/tests/test_keyboard.py @@ -0,0 +1,25 @@ +from src import sendkeys +from src import config + + +def test_sendkeys(): + sendkeys.send_text('Hello World') + + +def test_send_to(): + sendkeys.send_to('Sinusal', 'Hi, how are you?') + + +def test_pickup(): + conf = config.read_config(r'config.yaml') + sendkeys.send_pickup('Sinusal', 'Watcher\'s Eye', 11, 'Exalts', conf) + + +def test_wait(): + conf = config.read_config(r'config.yaml') + sendkeys.send_wait('Sinusal', conf) + + +def test_ty(): + conf = config.read_config(r'config.yaml') + sendkeys.send_ty('Sinusal', conf) \ No newline at end of file