Added sendkeys module.

This commit is contained in:
Oliver Hartmann 2021-03-14 13:20:22 +01:00
parent e817062f68
commit d67b574969
4 changed files with 63 additions and 1 deletions

View File

@ -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<date>\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d) (\d+) (\S+) \[(?P<level>\S+) (\S+) (\d+)\] (?P<channel>[#@%$&]?)(?P<ToFrom>To|From)?\s?(?P<guild><\S+>)? ?(?P<user>[^:]+): (?P<message>.*)'
re_trade: 'Hi, I would like to buy your (?P<item>.+) listed for (?P<amount>\d+) (?P<currency>\S+) in (?P<league>\S+) \(stash tab "(?P<tab>.+)"; position: left (?P<col>\d+), top (?P<row>\d+)\)'

View File

@ -1,2 +1,3 @@
pytest==6.2.2
pyyaml==5.4.1
pyyaml==5.4.1
pywinauto==0.6.8

32
src/sendkeys.py Normal file
View File

@ -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)

25
tests/test_keyboard.py Normal file
View File

@ -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)